首页 > 代码库 > T-SQL 递归

T-SQL 递归

WITH TEMP ([ID], [PARENTID])    AS (SELECT            UNIQUEID            ,PID        FROM [DBO].TB_DEPTINFO D        WHERE PID = @ParentId UNION ALL SELECT            UNIQUEID            ,PID        FROM [DBO].TB_DEPTINFO I        INNER JOIN TEMP            ON I.PID = TEMP.[ID])    SELECT        *    FROM TEMP

 

T-SQL 递归