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')
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
DECLARE @CommaSeperatedValues VARCHAR(MAX) SELECT @CommaSeperatedValues = COALESCE(@CommaSeperatedValues+',' , '') + names FROM #temp print @CommaSeperatedValues
good example
ReplyDeleteVery usefull link ,thanks
ReplyDelete