Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 multi rows to one row ??

Author  Topic 

joshherman
Starting Member

13 Posts

Posted - 2011-06-20 : 02:42:04
tabel1
------

col1
----
A
B


tabel2
------
fk desc
-------------
A X
A Y
A Z
B X
B Y

i want to create report like

col1 Desc
---- ----
A X,Y,Z
B X,Y

how the solution for it ?


thank

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2011-06-20 : 02:54:10
If you are using Sqlserver 2005 or greater

SELECT pm.fk,(SELECT P.[desc] + ','FROM tab P WHERE P.fk = PM.fk
ORDER BY P.[desc] FOR XML PATH('')) as colu_name
FROM table2 AS PM group by pm.fk;

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

joshherman
Starting Member

13 Posts

Posted - 2011-06-20 : 03:40:54
ok :) thank you
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2011-06-20 : 03:57:24
quote:
Originally posted by joshherman

ok :) thank you



Welcome

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -