日期:2014-05-17 浏览次数:20813 次
ALTER PROCEDURE [dbo].[XXXX]
@年度 varchar(10),
@报表人 varchar(20),
@部门 varchar(50)
AS
declare @Year varchar(10)
declare @Department varchar(10)
declare @StsDpt char(1)--'0' 或 '1'
BEGIN
set @Year = @年度
set @Department = @部门
if (@Department='') or (@Department = '1')
set @StsDpt='0'
else
set @StsDpt='1'
select right('00'+convert(varchar(2),datepart(month,a.cw_date)),2) 月份,
count(a.UG_ID) 票数,
f.departmentName 部门,
convert(decimal(9,2),sum(b.UsePrePaymentSum)) 扣预付,
convert(decimal(9,2),sum(a.latefee)) 应收滞纳金,
convert(decimal(9,2),sum(a.latefee - a.DerateLateFee)) 实收滞纳金,
convert(decimal(9,2),sum(a.gasfee+a.latefee-a.DerateLateFee)) 应收金额,
convert(decimal(9,2),sum(a.paycash)) 实收金额 from usegasdata a ,paymentrecord b,Frame_Department f
where a.payflowno = b.payflowno
and datepart(year,a.cw_date)=@Year
and (b.departmentId=@Department or @StsDpt=0)
and b.departmentId = f.departmentId
and a.status ='2'
and b.status ='0'
group by f.departmentName ,right('00'+convert(varchar(2),datepart(month,a.cw_date)),2)
order by f.departmentName ,right('00'+convert(varchar(2),datepart(month,a.cw_date)),2)
select @年度 年度,@报表人 报表人,@部门 部门