日期:2014-05-17 浏览次数:20407 次
create function [dbo].[combimeXsjhbh_str](
@fhjhbh varchar(20),
@fhjhid varchar(20),
@erpid varchar(20),
@khbm varchar(100)
)
returns varchar(200)
as
begin
declare @s varchar(800)
select @s=isnull(@s+',','')+ltrim(xsjhbh)
from fh_jhbh left join fh_jhbb on fh_jhbh.fhjhid = fh_jhbb.fhjhid
where jhysh=1 and fhjhbh=@fhjhbh and fh_jhbh.fhjhid=@fhjhid and erpid=@erpid and khbm=@khbm
return @s
end
create function [dbo].[combimeFbid_str](
@fhjhbh varchar(20),
@fhjhid varchar(20),
@erpid varchar(20),
@khbm varchar(100)
)
returns varchar(200)
as
begin
declare @s varchar(800)
select @s=isnull(@s+',','')+ltrim(fbid)
from fh_jhbh left join fh_jhbb on fh_jhbh.fhjhid = fh_jhbb.fhjhid
where jhysh=1 and fhjhbh=@fhjhbh and fh_jhbh.fhjhid=@fhjhid and erpid=@erpid and khbm=@khbm
return @s
end
--......表示还有很多的字段要取出来,这些字段我都用max函数取
select fhjhbh,fh_jhbh.fhjhid,erpid,......,dbo.combimeXsjhbh_str(fhjhbh,fh_jhbh.fhjhid,erpid,khbm) as xsjhbh
from fh_jhbh left join fh_jhbb on fh_jhbh.fhjhid = fh_jhbb.fhjhid
where 1=1 and jhysh=1 and jhyshjfsj >= '2012-11-01'
group by fhjhbh,fh_jhbh.fhjhid,erpid,khbm