October 15, 2010 at 1:07 am
Select * from Cus returns
1John
2 Bob
I need to return the all the rows from Cus table into a single string. The return is dynamic.
I do not know the number of rows returned
My result should be
@String = 1,John,2,Bob
October 15, 2010 at 7:26 am
DECLARE @cus TABLE (col1 int, col2 varchar(50));
INSERT INTO @cus
SELECT 1, 'John' UNION ALL
SELECT 2, 'Bob';
SELECT stuff((SELECT ',' + convert(varchar(10), col1) + ',' + col2
FROM @cus
ORDER BY col1
FOR XML PATH(''),TYPE).value('.','varchar(max)'),1,1,'')
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy