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
 General SQL Server Forums
 New to SQL Server Programming
 CONVERT DATA COLUMN TO ROW WTIH COMMA

Author  Topic 

paritosh
Starting Member

42 Posts

Posted - 2012-08-20 : 10:51:23
HI ALL,

HOW TO COVERT COLUMN DATA IN TO ROW WITH COMMA SEPARATOR

DATA LIKE THAT :-
TABLE NAME : - TEST
COLUMN NAME : - COL1

ORIGINAL DATA ARE :-

COL1
1
2
3
4
5
6
7
1
4
5

REQUIRED DATA ARE :-

1,2,3,4,5,6,7,1,4,5

HOW TO DO THIS ....

THANKS IN ADVANCE....


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-20 : 10:55:37
[code]
DECLARE @CSVList varchar(max)
SELECT @CSVList=STUFF((SELECT ',' + CAST(COL1 AS varchar(5))
FROM Table
ORDER BY Col1
FOR XML PATH('')),1,1,'')

SELECT @CSVList
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -