• I get 3 rows not 4, maybe I'm missing something.

    DECLARE @Start INT = 395;

    WITH Recur AS (

    SELECT [ColA], [ColB], [ColC], [ColD], [ColE], [ColF]

    FROM [dbo].[tmpTable]

    WHERE [ColA] = @Start

    UNION ALL

    SELECT t.[ColA], t.[ColB], t.[ColC], t.[ColD], t.[ColE], t.[ColF]

    FROM [dbo].[tmpTable] t

    INNER JOIN Recur r ON r.[ColD] = t.[ColA])

    SELECT [ColA], [ColB], [ColC], [ColD], [ColE], [ColF]

    FROM Recur;

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537