- February 8, 2017
- Posted by: user
- Category: Uncategorized
No Comments
Today i came across one interesting inbulit function of sql that is ‘COALESCE’. Using which i can get comma separated values of a column in sql table. I have explained how its been possible to me. Please have a look below.
[code:sql] SELECT * FROM university;
DECLARE @universityList varchar(100);
SELECT @universityList = COALESCE(@universityList + ‘,’, ”) +
CAST((universityName) AS varchar(5))
FROM university
SELECT @universityList as CSV; [/code]