I wanted my output something the below one.

  • Hello,

    Can you tell me how to display different values of rows in one single row.

    Suppose my output is something like this:

    id name marks

    001 abc 23

    001 abc 25

    001 abc 20

    001 abc 24

    001 abc 28

    002 def 19

    002 def 25

    002 def 26

    and this my expected output is this:

    id name marks

    001 abc 23,25,20,24,28

    002 def 19,25

    003 acs 26,20,22

    Please tell me how do i write the procedure query..?

    Can you give me an example for the above question in sqlserver 2005...??

  • The FOR XML PATH solution is one way to do it:

    SELECT

    id,

    name,

    STUFF(

    (SELECT ',' + CAST(t2.marks AS VARCHAR(10))

    FROM #temp t2

    WHERE t2.id=t1.id

    FOR XML PATH('')

    ),1,1,'') marks

    FROM #temp t1

    GROUP BY id,name



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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