|
楼主 |
发表于 2007-6-13 09:54:02
|
显示全部楼层
完整的存储过程
REATE PROCEDURE pa_Bservice_DisCount @fcmonth char(7),@fgsno varchar(10),@fwgsbh varchar(10),@Discount decimal(18,2) output AS
declare @month char(7)
declare @fupDiscount decimal(18,2) --上月折扣余额
declare @fDiscount decimal(18,2) --本月折扣金额
declare @fDiscount_db decimal(18,2) --本月调拨
declare @fDiscount_us decimal(18,2) --本月报销
declare @fgsname varchar(20)
select @fgsname=FDISPLAYNAME from opendatasource('sqloledb','data source=192.168.0.250;user id=saassword=perfect').perfect_system.dbo.TDEPT where EBH = @fgsno
--select name from newshop..fgs where fgsno=@fgsno
--取上月份
select @month=max(fcmonth) from Bservice_flag
--取上月折扣余额
select @fupDiscount=isnull(fDiscount,0) from Bservice_yj where fcmonth=@month and fgsno=@fgsno and fwgsbh=@fwgsbh
---取本月折扣金额
select @fDiscount=isnull(sum(fcash),0) from Bservice_zk where fcmonth=@fcmonth and fgsno=@fgsno and fwgsbh=@fwgsbh
---取本月调拨
select @fDiscount_db=isnull(sum(fcash),0) from Bservice_db where fcmonth=@fcmonth and fgsno=@fgsno and fwgsbh=@fwgsbh
---取本月报销
select @fDiscount_us=isnull(sum(b.JE),0) from opendatasource('sqloledb','data source=192.168.0.250;user id=saassword=perfect').ywbx.dbo.FWGSBXZB a, opendatasource('sqloledb','data source=192.168.0.250;user id=saassword=perfect').ywbx.dbo.FWGSMXB b where a.SQBH = b.SQBH and a.LZBZ = 1 and a.BXYF = @fcmonth and b.FWGSBH=@fwgsbh and a.SQBM =@fgsname
--返回可报销折扣(动态计算:上月折扣余额+本月折扣金额+本月调拨-本月报销)
select @discount=isnull(@fupDiscount,0)+isnull(@fDiscount,0)+isnull(@fDiscount_db,0)-isnull(@fDiscount_us,0)
GO |
|