declare @a varchar(1000) set @a='' select @a=','+@a+t1+' '+rtrim(t2) from tb select stuff(@a,1,1,'')
select @a=@a+','+t1+' '+rtrim(t2) from tb --修正
create table a(t1 varchar(10),t2 varchar(10)) insert into a select 'g001' , 'aaa' insert into a select 'g002' , 'bbb' insert into a select 'g003' , 'ccc'declare @v varchar(1000) set @v=' ' select @v=@v+t1+' '+t2+',' from a print @vg001 aaa,g002 bbb,g003 ccc,
create table a(t1 varchar(10),t2 varchar(10)) insert into a select 'g001' , 'aaa' insert into a select 'g002' , 'bbb' insert into a select 'g003' , 'ccc'declare @v varchar(1000) set @v=' ' select @v=@v+t1+' '+t2+',' from a set @v=left(@v,len(@v)-1) --修正一下去掉最后面的','! print @v g001 aaa,g002 bbb,g003 ccc
set @a=''
select @a=','+@a+t1+' '+rtrim(t2) from tb
select stuff(@a,1,1,'')
insert into a select 'g001' , 'aaa'
insert into a select 'g002' , 'bbb'
insert into a select 'g003' , 'ccc'declare @v varchar(1000)
set @v=' '
select @v=@v+t1+' '+t2+',' from a
print @vg001 aaa,g002 bbb,g003 ccc,
insert into a select 'g001' , 'aaa'
insert into a select 'g002' , 'bbb'
insert into a select 'g003' , 'ccc'declare @v varchar(1000)
set @v=' '
select @v=@v+t1+' '+t2+',' from a
set @v=left(@v,len(@v)-1) --修正一下去掉最后面的','!
print @v
g001 aaa,g002 bbb,g003 ccc
http://community.csdn.net/Expert/topic/5551/5551965.xml?temp=.8143885是关于删除重复列的问题!