pivot?!?

  • I have a table T1 with only one column.

    ID

    1

    2

    3

    I want to put all the records (separated by comma) in a single column of another table T2.

    ID

    1,2,3

    Is it possible to do this without using the cursors?

    Thank you.

  • You might be able to use this technique:

    declare @T1 table (Id int)

    insert @T1

    (Id)

    values (1),(2),(3);

    with vals(x) as (select ',' + cast(Id as varchar(5)) from @T1 t

    for xml path(''))

    select stuff(x,1,1,'') from vals

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • For an explanation on what Phil posted.

    http://www.sqlservercentral.com/articles/comma+separated+list/71700/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • thank you very much

  • Thank you Phil, very useful!

Viewing 5 posts - 1 through 4 (of 4 total)

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