例如表A
id     data
1      A
1      B
1      C
2      D
2      F

转换成表B
1     A+B+C
2     D+E

smerg是自定义函数
创建一个函数smerg:

create function smerg(@id int)
returns varchar(8000)
as
begin
declare @str varchar(8000)
set @str=''
select @str=@str+','+name from 表A where id=@id
set @str=right(@str,len(@str)-1)
return(@str)
End
go

--调用自定义函数得到结果
select distinct id,smerg(id) as name into 表B from 表A

select distinct id,dbo.smerg(id) as name into 表B from 表A

 

 

相关文章:

  • 2022-03-13
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-03-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2022-02-28
相关资源
相似解决方案