sql 一个小例子。行转列 以,号隔开

create table #1
(
   a int,
   b  varchar(10)
)

insert into #1 values(1,'aa')


insert into #1
select 1,'1a' union all
select 2,'1b' union all
select 3,'1c'
go
select * from #1

declare @str varchar(8000)
declare @bb varchar(20)
select @str= isnull(@str+',','')+b
from #1
select @str

你可能感兴趣的:(sql)