Friday, September 21, 2012

Get Comma Delimited List in Sql Server

How Get Comma Delimited List in Sql Server?

Solution:- 

DECLARE @state_name nvarchar(100)
SELECT @state_name = COALESCE(@state_name,'') + COALESCE(state_name,'') + ',' FROM states
WHERE state_name IS NOT NULL
SET @state_name = SUBSTRING(@state_name,0,LEN(RTRIM(@state_name)))
--use for print list 
PRINT @state_name

Example:-



 

No comments:

Post a Comment