Используются оконные функции и объединение:
DECLARE @t TABLE ([Id] INT, [Code] CHAR(2), [Name] CHAR(2), [SysName] VARCHAR(10))
INSERT INTO @t values
(1 , 'D1', 'N1', Null ), (2 , 'D1', Null, Null ), (3 , 'D1', 'N1', 'N-1' ), (4 , 'E2', 'N2', Null ), (5 , 'E2', 'N2', Null ), (6 , 'E2', 'N2', Null )
, (7 , 'X3', Null, Null ), (8 , 'X3', Null, 'N-3' ) , (9 , Null, Null, Null ), (10, Null, Null, Null ), (11, 'Z4', 'W2', 'N-44'), (12, 'Z4', 'W2', 'N-44' )
;WITH t AS (
SELECT DISTINCT
[code]
, COALESCE([name], max([name]) OVER(PARTITION BY [code])) AS [Name]
, COALESCE([sysname], COALESCE(MAX([sysname]) OVER(PARTITION BY [code], [name]), MAX([sysname]) OVER(PARTITION BY [code]))) AS [SysName]
FROM @t
WHERE [code] IS NOT NULL)
SELECT MIN(t2.id), t.Code, t.Name, t.SysName
from @t t2
INNER JOIN t ON t.code = t2.code AND ISNULL(t.[Name], 'null') = ISNULL(t2.[Name], 'Null') AND ISNULL(t.[SysName], 'Null') = ISNULL(t2.[SysName], 'Null')
GROUP BY t.Code, t.Name, t.SysName