Comma separated values of table column in sql server

Hi Friends,

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 university
	SELECT @universityList as CSV; 

Result in comma separated value

Comments

NOTE : Comments are moderated, and will not appear until the author has approved them.
Post a Comment
  1. Leave this field empty

Required Field