SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 multi rows to one row ??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

joshherman
Starting Member

13 Posts

Posted - 06/20/2011 :  02:42:04  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
1007 Posts

Posted - 06/20/2011 :  02:54:10  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
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 - 06/20/2011 :  03:40:54  Show Profile  Reply with Quote
ok :) thank you
Go to Top of Page

senthil_nagore
Flowing Fount of Yak Knowledge

India
1007 Posts

Posted - 06/20/2011 :  03:57:24  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000