Sqlserver查询结果,让某列结果合并一列并且逗号分隔。
create function [dbo].[mergeName](@Id bigint) returns nvarchar(500)
as
begin
declare @str nvarchar(500)
set @str = ''
select @str = @str + ',' + cast(CompanyUserName as nvarchar(500)) + cast(Mobile as nvarchar(500)) from dbo.CRMCompanyUser where Id in
( select companyUserId from dbo.CRMSalesRecruitmentJoinCompanyContact where SalesRequirementId=@Id )
if(len(@str)>1)
set @str = right(@str , len(@str) - 1)
return @str
end