34,576
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据:[tablename]
if object_id('[tablename]') is not null drop table [tablename]
go
create table [tablename]([id] int,[Title] varchar(1))
insert [tablename]
select 1,'A' union all
select 2,'B' union all
select 3,'C' union all
select 4,'D' union all
select 5,'E' union all
select 6,'F'
declare @S nvarchar(100)
select @S=isnull(@S+',','')+CAST([id] AS VARCHAR) id from [tablename]
SELECT @S
/*
id
----------------------------------------------------------------------------------------------------
1,2,3,4,5,6
*/