已有关联,实际上是业务员每周打跟进客户报表时需要所有的跟进记录汇总下
网上找到如下参考解决了
-----多行记录结果合并为一列------
select province, dbo.fun_GetProvinceCity(province) as CName from city
group by province
if object_id('fun_GetProvinceCity') is not null
drop function fun_GetProvinceCity
GO
create function fun_GetProvinceCity(@proviceName varchar(50))
returns varchar(8000)
AS
begin
declare @cityName varchar(8000)
set @cityName=''
select @cityName=@cityName+','+CName from city where province=@proviceName
return stuff(@cityName,1,1,'')
end
------------------返回结果---------------------
/*
province CName
广东省 广州,深圳,佛山
湖南省 邵阳,岳阳,衡阳,永州,株洲,长沙
江西省 南昌
*/