Retrieving a specific column as comma separated values

  • SELECT d.EmployeeID,d.Name,d.Department,d.Manager,

    STUFF(((SELECT ', '+e.EmailAddress AS "text()"

    FROM EmployeeEmailAddresses e

    WHERE e.EmployeeID=d.EmployeeID

    ORDER BY e.EmailAddress

    FOR XML PATH(''),TYPE).value('./text()[1]','VARCHAR(1000)')),1,2,'') AS EmailAddresses

    FROM EmployeeDetails d

    ORDER BY d.Name;

    ____________________________________________________

    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
  • Thanks Mark-101232!

    Works like a charm!

Viewing 2 posts - 1 through 3 (of 3 total)

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