create table # (id varchar(10)) insert into # select 'a' union all select 'b' union all select 'c' union all select 'd' declare @s varchar(100) select @s='' select @s=@s+id from # print @sabcd
1楼正解!/********create table # (id varchar(10)) insert into # select 'a' union all select 'b' union all select 'c' union all select 'd' ***********/这是建立测试环境,又不是让你连接! 就一个动态语句就可以实现了! /* declare @s varchar(100) select @s='' select @s=@s+id from # print @s */
(id varchar(10))
insert into #
select 'a' union all
select 'b' union all
select 'c' union all
select 'd' ***********/这是建立测试环境,又不是让你连接!
就一个动态语句就可以实现了!
/*
declare @s varchar(100)
select @s=''
select @s=@s+id from #
print @s
*/
那我得拼接1000次?----------------
楼主不会把我写的简单的化为函数吗?
就可以直接用select dbo.函数名(字段名)from 表得到该字段合并的结果