Find multiple status in one Column from different rows

  • SELECT t1.CustomerName AS Customer,

    STUFF((SELECT ',' + t2.Status AS "text()"

    FROM dbo.Customers t2

    WHERE t2.CustomerName = t1.CustomerName

    ORDER BY t2.Status

    FOR XML PATH(''),TYPE).value('./text()[1]','varchar(1000)'),1,1,'') AS Relations

    FROM dbo.Customers t1

    GROUP BY t1.CustomerName

    ORDER BY t1.CustomerName;

    ____________________________________________________

    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

Viewing post 1 (of 2 total)

You must be logged in to reply to this topic. Login to reply