日期:2014-05-17 浏览次数:20389 次
create table tb(col1 varchar(5),
col2 varchar(5),
col3 varchar(5),
col4 varchar(5),
col5 varchar(5),
col6 varchar(5)
)
insert into tb
select 'a','b','c','m1','m2','m3'
union all select 'a','b','c','m4','m5','m6'
union all select 'a','b','c','m7','m8','m9'
select * from tb
declare @s varchar(1000)
set @s=''
select @s=@s+col1+char(9)+col2+char(9)+col3+char(9)
from (select distinct col1,col2,col3 from tb)t
select @s=@s+col4+char(9)+col5+char(9)+col6+char(9)
from tb
print @s
/*
a b c m1 m2 m3 m4 m5 m6 m7 m8 m9
*/