Saturday, 4 May 2013

select Column data in Comma Separated string


Column data in Comma Separated string

hi, Check this article for select a column data in comma separated string.

Step1:: Create a table

create table #temp(id int,names varchar(50))

Step2:: Insert A data in table

insert into #temp(id,names)values(1,'w') insert into #temp(id,names)values(2,'c') insert into #temp(id,names)values(3,'a') insert into #temp(id,names)values(4,'m')

Step3:: Execute following query and check a output

DECLARE @CommaSeperatedValues VARCHAR(MAX) SELECT @CommaSeperatedValues = COALESCE(@CommaSeperatedValues+',' , '') + names FROM #temp print @CommaSeperatedValues


2 comments:

8451831077