日期:2014-05-17 浏览次数:20705 次
exec pro_baobiao 2012,1,3,'柴油'
/*
月份/部门 转运部 作业部 车队 仓储部 维修部 合计
---------- ----------- ----------- ----------- ----------- ----------- -----------
1 33809 55852 49255 24111 5637 168664
2 32280 53435 46083 25273 5869 162940
3 32198 52052 47500 23901 6945 162596
合计 98287 161339 142838 73285 18451 494200
上年同期 101792 168729 145406 79538 18991 514456
同比 -3505 -7390 -2568 -6253 -540 -20256
*/
GO
if object_id('pro_baobiao') is not null drop proc pro_baobiao
GO
/*
该过程为解CSDN帖而建
功能:格式化返回报表
参数: @year 年份
@BgnMonth 起始月份
@EndMonth 结束月份
@GoodsName 物料名称
作者:磊仔(tanleittl)
*/
CREATE PROC pro_baobiao
@year int,
@BgnMonth int,
@EndMonth int,
@GoodsName varchar(50)
AS
set nocount on
;with CET1 as
(
select cast(b.[month] as varchar(10))[月份/部门],a.GetUseDept,GoodsQTY from test a, dbo.fn_monthlist(26) b
where a.GetUseDate >= b.StartT and a.GetUseDate < b.EndT
and b.[year] = @year and b.[month] >= @BgnMonth and b.[month] <= @EndMonth and GoodsName = @GoodsName
)select *,[转运部] + [作业部] + [车队] + [仓储部] +&nbs