Declare @table table (CityName varchar(50))
insert into @table values ('London')
insert into @table values ('Birmingham')
insert into @table values ('Manchester')
insert into @table values ('Glasgow')
1._________________________________________________________________
declare @csv as varchar(500)
select @csv = case when @csv is null then ''
else @csv + ',' end + CityName from @table
select @csv as csv
2.__________________________________________________________________
declare @csv as varchar(500)
SELECT @CSV = COALESCE(@csv + ', ','') + CityName
FROM @table
select @csv as csv
3.__________________________________________________________________
declare @csv as varchar(500)
set @csv = (select CityName + ',' from @table for xml path(''))
select @csv as csv
No comments:
Post a Comment