• OK. Looks to me like you're pretty new to SQL. So, can I suggest that you take some time out to ensure you understand how both examples work?

    ;WITH cte ( requestid, approvallist, approvelevelname, length )

    AS (SELECT requestid,

    CAST('' AS VARCHAR(8000)),

    CAST('' AS VARCHAR(8000)),

    0

    FROM dbo.ts_status

    GROUP BY requestid

    UNION ALL

    SELECT p.requestid,

    CAST(approvallist + CASE

    WHEN length = 0 THEN ''

    ELSE ', '

    END + p.approvelevelname AS VARCHAR(8000)),

    CAST(p.approvelevelname AS VARCHAR(8000)),

    length + 1

    FROM cte c

    INNER JOIN dbo.ts_status p

    ON c.requestid = p.requestid

    WHERE p.approvelevelname > c.approvelevelname)

    SELECT requestid,

    approvallist

    FROM (SELECT requestid,

    approvallist,

    Rank() OVER ( PARTITION BY requestid ORDER BY length DESC )

    FROM cte) d ( requestid, approvallist, rank )

    WHERE rank = 1


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/