Here I will explain how to get comma separated string of column value using stuff function.
DECLARE @Name_Mast TABLE (
[Name] VARCHAR(20)
)
INSERT INTO @Name_Mast ( [Name] )
VALUES ( 'Nikhil' ), ( 'Saumya' ), ('Keyur'), ('Nikunj')
SELECT STUFF((SELECT ',' + [Name]
FROM @Name_Mast
ORDER BY [Name]
FOR XML PATH('')), 1, 1, '') AS [Output]
OUTPUT: "Keyur,Nikhil,Nikunj,Saumya"
Comments
Post a Comment