WITH KeyRecursive AS ( SELECT * FROM table_2 WHERE [key] = 6 UNION ALL SELECT k.* FROM table_2 k JOIN KeyRecursive kr ON kr.ReplacementKey = k.[key] ) SELECT * FROM KeyRecursive>I have a table with the following structure:
>Key StartDate StopDate ReplacementKey ReplacementDate >------------------------------------------------------------------------------------------------------- >1 2000-04-12 13:02:00.670 2002-10-17 13:43:56.000 NULL NULL >6 2000-12-12 14:11:25.000 2001-05-29 17:02:17.000 119 2006-05-21 09:53:06.740 >17 2001-09-10 09:34:11.000 2006-05-11 11:02:03.000 NULL NULL >137 2003-02-03 16:34:37.000 2005-08-05 11:44:58.000 147 2006-06-21 10:53:06.750 >141 2003-02-04 09:43:48.000 2005-08-05 11:44:58.000 236 2006-06-21 10:53:06.750 >>