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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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 ??
 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  
 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.05 seconds. Powered By: Snitz Forums 2000