Daily problems and issues that are hard to resolve about SSMS,SSRS,SSIS,SSAS,DTS,Agent, Optimization, Administration, Always On, Clustering, Point in Time recovery and more...
Search This Blog & Web
Friday, May 22, 2009
Returning Comma seperated Values in SQL Server 2005
Declare @vComma Varchar(max);
Select @vComma = COALESCE(@vComma+';','') + column1 from table1
select @vComma
I have 5 values in Unique table against Val column and this command will return all values as ; seperated
Yes this works and is good but their must be some other ways because I saw people using function some where and XML also. Can any one have example for this.
3 comments:
Yes this works and is good but their must be some other ways because I saw people using function some where and XML also.
Can any one have example for this.
Select column +’,’ as [Text()] from tablename for xml path(‘’)
is another way around to return xml column with , seperation
Select cast(intregistrationid as varchar(10) ) +','
from te_registration
where intstatus = 174 and intseasonid = 1
for xml path('')
[text()] causes problems as column alias. because it creates xml tag with this name.
Post a Comment