日期:2014-05-17 浏览次数:20391 次
declare @t table (id int)
declare @s varchar(128)=''
insert into @t
select 1 union all select 2 union all select 3
select @s =@s+CONVERT(varchar(8),id)+',' from @t
select @s as S
--------------------
(3 行受影响)
S
-------------
1,2,3,
(1 行受影响)
--> 测试数据: @T
declare @T table (id int)
insert into @T
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7
declare @sql varchar(200)
select @sql=isnull(@sql+',','')+ltrim(id) from @T
select @sql
/*
1,2,3,4,5,6,7
*/