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 |
Ciupaz
Posting Yak Master
232 Posts |
Posted - 2012-11-23 : 08:49:37
|
Hello all,I have a query that returns me these values:Plant UPBRINDISI BR1BRINDISI BR3BRINDISI BR3BRINDISI BR4PIACENZA PZ1S.FILIPPO SF3BRINDISI BRTestBRINDISI BR-FVPIACENZA PZ4I have intead to get this result: BRINDISI BR1,BR2,BR3,BR4,BRTest,BR-FVPIACENZA PZ1,PZ4S.FILIPPO SF3grouped by "Plant" field e in the second field a concatenatio of UP collegated..How can I obtain this? Thanks in advance. Luigi |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-11-23 : 08:56:55
|
Just replace red marked part with your table name-- Get CSV valuesSELECT t.Plant, STUFF((SELECT ',' + s.UP FROM TestTable s WHERE s.plant = t.plant FOR XML PATH('')),1,1,'') AS CSVFROM TestTable AS tGROUP BY t.plantGO--Chandu |
|
|
Ciupaz
Posting Yak Master
232 Posts |
Posted - 2012-11-23 : 09:17:09
|
Perfect, thank you very much Bandi. I never get this solution by myself.Luigi |
|
|
|
|
|