临时表汇总金额

create proc [dbo].[sp1getPropertyCenterFee]
@userid int,
@areaid VARCHAR(100)='0'
as

declare @parknumber varchar(50)

-------------------------------@parknumber 取值 begin--------------------------

IF @areaid='0'
select @parknumber=dbo.fn1GetparkNumber(@userid,@areaid)
ELSE IF @areaid='-1'
select @parknumber=dbo.fn1GetparkNumber(@userid,0)
ELSE
SET @parknumber=@areaid
-------------------------------@parknumber 取值 end --------------------------
declare @tmp table( PayCharge decimal(18,2),RealPayMoney decimal(18,2),PrepaidMoney decimal(18,2) )
insert into @tmp(PayCharge)
exec ('select isnull( sum(isnull(PayCharge,0)),0) PayCharge from PLParkOutRecoed where ParkNumber in('+@parknumber+')')
insert into @tmp(RealPayMoney)
exec ('select isnull(sum(isnull(RealPayMoney,0)),0) RealPayMoney from (

SELECT * FROM dbo.Comm_AccountNoAndWeixinOrderNo a LEFT JOIN dbo.Comm_RealPayment b ON a.WexiOrderNo=b.OrderNo
RIGHT JOIN dbo.Account c ON a.AccountNo=c.AccountNo
WHERE a.OStatus=0 AND c.AreaID=15) where areaid in('+@parknumber+')')
insert into @tmp(PrepaidMoney)
exec ('select isnull(sum(isnull(PrepaidMoney,0)),0) PrepaidMoney from (

SELECT * FROM dbo.Comm_AccountNoAndWeixinOrderNo a LEFT JOIN dbo.Comm_RealPayment b ON a.WexiOrderNo=b.OrderNo
RIGHT JOIN dbo.Account c ON a.AccountNo=c.AccountNo
WHERE a.OStatus=0 AND c.AreaID=15) where areaid in('+@parknumber+')')
select isnull(SUM(ISNULL(PayCharge,0)),0) 'plfee', SUM(ISNULL(RealPayMoney,0)) 'propertyfee',SUM(ISNULL(PrepaidMoney,0)) 'peopertyyufee' from @tmp
View Code

 

posted @ 2015-11-18 17:30  Mark1997  阅读(214)  评论(0编辑  收藏  举报