July 30, 2011 at 3:44 am
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...??
July 30, 2011 at 6:20 am
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
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply