SQL
Thursday, 6 January 2011
Converting Multiple Rows into a CSV String (Set Based Method)
Prod_Code
---------
2001
2002
2003
2004
I need to end up with '2001,2002,2003,2004'.
Query:
=======
declare @str varchar(8000)
select @str = COALESCE(@str + ', ','') + convert(varchar(4),Col_name)
from Table_Name
select @str
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment