Contact Us

 Admin User     Feb,08 2017

Comma Separated Values of Table Column in SQL Server

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.

 SELECT * FROM university;DECLARE @universityList varchar(100);SELECT @universityList = COALESCE(@universityList + ',', '') +CAST((universityName) AS varchar(5))FROM universitySELECT @universityList as CSV; 

Result in comma separated value