Table Name > tbmap
Fields > Place
Data > Amritsar
Bhutan
Kerala
Query to generate comma-separated list from one individual column data
from database table in sql server using COALESCE()
Query >
DECLARE @List VARCHAR(8000)
SELECT @List = COALESCE(@List + ',', '') + CAST(Place AS VARCHAR)
FROM tbmap
where Place='PLACENAME'
SELECT @List as Place
Output :
Amritsar,Bhutan,Kerala
Fields > Place
Data > Amritsar
Bhutan
Kerala
Query to generate comma-separated list from one individual column data
from database table in sql server using COALESCE()
Query >
DECLARE @List VARCHAR(8000)
SELECT @List = COALESCE(@List + ',', '') + CAST(Place AS VARCHAR)
FROM tbmap
where Place='PLACENAME'
SELECT @List as Place
Output :
Amritsar,Bhutan,Kerala
No comments:
Post a Comment