Y si haces algo asi:
Código SQL:
Ver originalCREATE TABLE #temp
(
code INT,
iencucod INT,
duracion INT
)
INSERT INTO #temp VALUES (1,2999,1062)
INSERT INTO #temp VALUES (2,2999,610)
INSERT INTO #temp VALUES (3,2999,34)
INSERT INTO #temp VALUES (4,6170,447)
INSERT INTO #temp VALUES (5,15729,1148)
INSERT INTO #temp VALUES (6,15729,241)
INSERT INTO #temp VALUES (7,15729,53)
INSERT INTO #temp VALUES (8,38314,1029)
INSERT INTO #temp VALUES (9,38314,256)
SELECT code,duracion,iencucod FROM #temp WHERE
CONVERT(VARCHAR(20),duracion) + '#' + CONVERT(VARCHAR(20),iencucod) IN
(
SELECT CONVERT(VARCHAR(20),MAX(duracion)) + '#' + CONVERT(VARCHAR(20),iencucod) FROM #temp GROUP BY iencucod
)
Saludos!!