two rows into one by comma delimited

  • hi i have the below question , but not sure how to write the code , iam a new b ,can somebody help me out please

    a  1

    a  2

    a  3

    b  1

    i want the results to be

    a 1,2,3

    b 1

  • This has got to be one of the most frequently asked questions, and there is likely an article on it (which if I find, I'll start linking to), but in the meantime, here is an example of how it can be done.

     

     

  • May be it will help!

    USE pubs

    GO

    DECLARE @title_ids varchar(8000), @delimiter char

    SET @delimiter = ','

    SELECT @title_ids = COALESCE(@title_ids + @delimiter, '') + title_id FROM titles

    SELECT @title_ids AS [List of Title IDs]

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

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