Me lo ganaste gerireshef jejeje
Código SQL:
Ver originalCREATE TABLE #temp
(
id VARCHAR(5),
jerarquia VARCHAR(20),
parentid VARCHAR(5)
)
INSERT INTO #temp VALUES ('01','1.00.00',NULL)
INSERT INTO #temp VALUES ('02','1.10.00','01')
INSERT INTO #temp VALUES ('03','1.10.10','02')
INSERT INTO #temp VALUES ('04','2.00.00',NULL)
INSERT INTO #temp VALUES ('05','2.10.00','04')
SELECT * FROM #temp WHERE id NOT IN (SELECT parentid FROM #temp WHERE parentid IS NOT NULL)
saludos!!