how to change multiple records in one record

  • hi,

    i have a query i.e.

    select project, description from table

    with results

    chocolate | white

    chocolate | black

    chocolate | brown

    sugar | black

    vinegar | yellow

    i would like to get a result like:

    chocolate | white, blakc, brown

    sugar | black

    vinegar | yellow

    so I would like to get all values of one project in one records included with separators/a space in it

  • Create table test

    (project varchar(50),

    descripation varchar(50)

    )

    Insert test

    SELECT 'chocolate' ,'white'

    UNION ALL

    SELECT 'chocolate' ,' black'

    UNION ALL

    SELECT 'chocolate' ,' brown'

    UNION ALL

    SELECT 'sugar' ,' black'

    UNION ALL

    SELECT 'vinegar' ,'yellow'

    SELECT DISTINCT project,

    STUFF( (SELECT ',' + descripation FROM test WHERE Test.project = T.project FOR XML PATH('')) ,1,2,'')

    FROM test T

  • i am getting the error

    `the multipart identifier project could not be found`

  • bauke.dijkstra (4/14/2015)


    i am getting the error

    `the multipart identifier project could not be found`

    Without your code it is hard to give an answer.

  • Create table bstest

    (project varchar(50),

    description varchar(50)

    )

    Insert bstest (project, description)

    (select project, description from table)

    ** insert 19 rows **

    SELECT DISTINCT project,

    STUFF( (SELECT ',' + description FROM bstest WHERE bstest.project = T.project FOR XML PATH('')) ,1,2,'')

    FROM bstest T

  • bauke.dijkstra (4/14/2015)


    Create table bstest

    (project varchar(50),

    description varchar(50)

    )

    Insert bstest (project, description)

    (select project, description from table)

    ** insert 19 rows **

    SELECT DISTINCT project,

    STUFF( (SELECT ',' + description FROM bstest WHERE bstest.project = T.project FOR XML PATH('')) ,1,2,'')

    FROM bstest T

    So you have a table named "table"? (select project, description from table)

  • i think i changed something. now it is working thanks

  • Removed

    -- Gianluca Sartori

Viewing 9 posts - 1 through 8 (of 8 total)

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