Advertisements

SQL-BOX.COM

–SQL Server Storage

script to merge column rows to single row seperated by comma,

Using STUFF function in sql serevr a column values can be retrieved as single value row, values seperated by comma’s.

 

SELECT STUFF( (
SELECT ', ' + [Name] FROM -- create comma separated values(
SELECT [Name] FROM sys.databases WHERE database_id >6 --Your query here
) T FOR XML PATH('')
) ,1,1,'') AS [Name]
Go
STUFF- Reference 

 
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: