How to get multiple row[columnvalue] into one column

  • Wasn't to sure how to describe the question here goes:

    Basically I have the following query that returns the following data

    Query:

      SELECT

      TASK_ID,

      TU.USER_ID,

      ASSIGNATION

      FROM TASK_USER TU

      where TASK_ID = 9174

      and TU.ASSIGNATION = 0

     

        union all

      SELECT

      TASK_ID,

      TU.USER_ID,

      ASSIGNATION

      FROM TASK_USER TU

      where TASK_ID = 9174

      and TU.ASSIGNATION = 1

    Results:

    TaskID   UserID   Assignment

    9174        1           0

    9174       10           0

    9174        16          1

    9174        18          1

    I want to convert this result set into a temp table created as the one below

    CREATE TABLE #Users

    (

        TaskID int, 

        AssignedUsers varchar(50),

        Reviewers varchar(50)

    So the select from the temp table above will look like this:

    TaskID   AssignedUsers Reviewers

    9174        1,10              16,18

    Any ideas? I've seen some pretty complex examples but I'm sure I've done this before in the past, just can't recall quite how.

    Thanks for the help,

    GP

  • Ref this post.

    has a couple links

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=338&messageid=342272

    Do a search on scripts, or discussions with concatenate strings and tons of stuff comes up.

  • Will do...thanks alot...it's been a while since I've been on the site.

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

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