How to convert the column data to comma separated in Single Row IN SQL

I have a table "sampledata"  with data like


id    city
1     Pune
2     Banglore
3    Mumbai
4    Nagpur


------------------------------------
DECLARE @list nvarchar(max)

SELECT @list = COALESCE(@list + ', ', '') + CAST(city AS varchar(100))
FROM sampledata

SELECT @list as List



-----------------------Output----------------

 Pune, Banglore, Mumbai, Nagpur


Comments

Popular posts from this blog

GROUP BY, CUBE, ROLLUP and SQL SERVER 2005

How to get content of Ckeditor & Fckeditor using Javascript

How to Fix Error- Sys.WebForms.PageRequestManagerTimeoutException - The server request timed out