Logic for converting a column values into a CSV record using ISNULL, COALESCE functions
declare @Temp Table(Val int)
declare @CSV varchar(2000)
insert into @Temp values(1)
insert into @Temp values(2)
insert into @Temp values(3)
insert into @Temp values(4)
insert into @Temp values(5)
select @CSV = isnull(@CSV + ',', '') + convert(varchar,val)
from @Temp
select @CSV
set @CSV = NULL
select @CSV = coalesce(@CSV + ',', '') + convert(varchar,val)
from @Temp
select @CSV
declare @CSV varchar(2000)
insert into @Temp values(1)
insert into @Temp values(2)
insert into @Temp values(3)
insert into @Temp values(4)
insert into @Temp values(5)
select @CSV = isnull(@CSV + ',', '') + convert(varchar,val)
from @Temp
select @CSV
set @CSV = NULL
select @CSV = coalesce(@CSV + ',', '') + convert(varchar,val)
from @Temp
select @CSV
Comments
Post a Comment