sql 中实现某个表中某字段拼接到一起

create Function [dbo].[GetJoinChar](@cghth varchar(50))
Returns varchar(5000)
As
Begin
Declare @s_sgdh varchar(5000)
Set @s_sgdh = ''
Select @s_sgdh = @s_sgdh + [拼接字段] + ','
from 表1 qd,表2 zy
where qd.cghtzyid=zy.cghtzyid and zy.关联字段= @cghth
Set @s_sgdh = Left(@s_sgdh, len(@s_sgdh) -1 )
Return(@s_sgdh)
End

posted @ 2017-02-23 15:06  小鱼儿儿  阅读(2839)  评论(0编辑  收藏  举报