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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query results RT to LT instead of top to bottom

Author  Topic 

joemama
Posting Yak Master

113 Posts

Posted - 2008-08-11 : 20:02:24
is there a way to have a query show data like this...

FAC FACNAME FACSUBNAME
1 RWC ALM,COP,DGR



and not this

FACID FACSUBIDFACNAME FACSUBNAME
1 2 RWC ALM
1 3 RWC COP
1 3 RWC COP
1 4 RWC DGR


I have a facility table and a facilitysub table and need to have results show as in the first example

any help would be appreciated

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-11 : 22:20:08
use PIVOT operator


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-11 : 23:53:15
[code]SELECT DISTINCT FAC,FACNAME,STUFF(SELECT FACSUBNAME + ',' AS [text()] FROM YourTable WHERE FAC=t.FAC AND FACNAME =t.FACNAME ORDER BY FACSUBNAME FOR XML PATH('')),1,1,'')
FROM YourTable t[/code]
Go to Top of Page
   

- Advertisement -