sql server 类oracle vm_contact() 函数创建

CREATE FUNCTION dbo.fun_orgname(@id int)
RETURNS varchar(8000)
AS
BEGIN
     DECLARE @str varchar(8000)
     SET @str = ''
  select  @str = @str + ',' +r.NAME from PRINCIPAL_ORG t left join ORG r on t.ORG_ID=r.ID where t.PRINCIPAL_ID=@id
     RETURN STUFF(@str, 1, 1, '')
END
GO

原文地址:https://www.cnblogs.com/hongfu/p/4911229.html