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.
Author |
Topic |
evets
Starting Member
3 Posts |
Posted - 2012-12-20 : 08:45:24
|
Hello,I must create a query usable through excel, pointing a sql 2005.I have a similar situation:CLIENTS-------ID---1234PROTOCOLS------------------IDCLIENT | NUMBERS------------------1 AA1 BB2 XX2 YY2 ZZI wish to obtain Clients Protocols--------------------------- 1 AA, BB 2 XX, YY, ZZor, at least:Clients Protocols Protocols2 PRotocols3 ...----------------------------------------------------------------- 1 AA BB 2 XX YY ZZ ...I Cannot forsee how many occurrencies of each record I will have, but I could set a Maximum (5 or 10 max).Is there a way to obtain this ?Thank youStefano |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2012-12-20 : 10:49:48
|
Check the bottom of this post on how to pivot dynamichttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=181589 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-20 : 11:19:13
|
for former output useSELECT Clients,STUFF((SELECT ',' + NUMBER FROM PROTOCOLS WHERE IDCLIENTS = c.ID FOR XML PATH('')),1,1'') AS ProtocolsFROM CLIENTS c ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
evets
Starting Member
3 Posts |
Posted - 2012-12-20 : 11:35:09
|
Thank you but I obtain this:SELECT prpratiche,STUFF((SELECT ',' + att_descrizione FROM agattivita WHERE att_idpratica = c.pra_id FOR XML PATH('')),1,1'') AS ProtocolsFROM prpratiche cMsg 102, Level 15, State 1, Line 3Incorrect syntax near ''.thank you very much !quote: Originally posted by visakh16 for former output useSELECT Clients,STUFF((SELECT ',' + NUMBER FROM PROTOCOLS WHERE IDCLIENTS = c.ID FOR XML PATH('')),1,1'') AS ProtocolsFROM CLIENTS c ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-20 : 11:43:09
|
missed a commaSELECT prpratiche,STUFF((SELECT ',' + att_descrizione FROM agattivita WHERE att_idpratica = c.pra_id FOR XML PATH('')),1,1,'') AS ProtocolsFROM prpratiche c ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2012-12-20 : 11:44:26
|
quote: Originally posted by evets Thank you but I obtain this:SELECT prpratiche,STUFF((SELECT ',' + att_descrizione FROM agattivita WHERE att_idpratica = c.pra_id FOR XML PATH('')),1,1,'') AS ProtocolsFROM prpratiche cMsg 102, Level 15, State 1, Line 3Incorrect syntax near ''.thank you very much !quote: Originally posted by visakh16 for former output useSELECT Clients,STUFF((SELECT ',' + NUMBER FROM PROTOCOLS WHERE IDCLIENTS = c.ID FOR XML PATH('')),1,1'') AS ProtocolsFROM CLIENTS c ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
|
|
|
|
|