This is a very simple and efficient way of getting values of a column in a delimited string.
USE AdventureWorks 
GO 
DECLARE @nameslist VARCHAR(MAX) 
SELECT @nameslist = COALESCE(@nameslist+',' ,'') + Name 
FROM Production.Product 
SELECT @nameslist
Using the COALESCE function ensures that result set does not get affected by null values. For more information about this function check out this link.
No comments:
Post a Comment