如何编写比较月末值的 SSRS 报告?
How to write SSRS report that compares end of month values?
我有一个 SSRS (SQL Server 2008 R2) 报告,它显示了关于在特定时间点基于 reportDate
参数满足特定条件的项目的聚合信息。此报表用于计算月末值。
我需要扩展报告以根据 numberOfMonths
参数显示与之前(或后续)月份的比较。例如 reportDate=2015-01-01
和 numberOfMonths=4
我希望得到一份报告,比较 1 月 1 日、2 月 1 日、3 月 1 日和 4 月 1 日的结果。
我不认为我可以使用一个范围b/c一些在该范围的某些部分符合标准的项目可能在月末日期不符合标准。
我能想到的最好的类比是 AR 报告,您可以在其中汇总月底按客户分组的未付发票。在一个月内创建但在月底前支付的发票不会显示在任何地方,但在 1 月 15 日创建并在 3 月 15 日支付的发票将包含在 2 月 1 日和 3 月 1 日列的总和中。
在 SSRS 中完成此任务的最佳方法是什么?
我无法找到原生 SSRS 解决方案,因此使用了循环几个月的存储过程:
@reportDate datetime,
@numberOfMonths int
DECLARE @results TABLE
(
ID int,
Column2 nvarchar(50),
Column3 nvarchar(50),
)
-- get the end of month values for each month
WHILE @numberOfMonths > 0
BEGIN
DECLARE @date datetime
SET @date = DATEADD(month, DATEDIFF(month, 0, @reportDate) - @numberOfMonths + 2, 0)
INSERT INTO @results
SELECT ID, Column1, Column2
FROM MyTable
WHERE ConditionToIncludeInThisPeriod
SET @numberOfMonths -= 1
END
我有一个 SSRS (SQL Server 2008 R2) 报告,它显示了关于在特定时间点基于 reportDate
参数满足特定条件的项目的聚合信息。此报表用于计算月末值。
我需要扩展报告以根据 numberOfMonths
参数显示与之前(或后续)月份的比较。例如 reportDate=2015-01-01
和 numberOfMonths=4
我希望得到一份报告,比较 1 月 1 日、2 月 1 日、3 月 1 日和 4 月 1 日的结果。
我不认为我可以使用一个范围b/c一些在该范围的某些部分符合标准的项目可能在月末日期不符合标准。
我能想到的最好的类比是 AR 报告,您可以在其中汇总月底按客户分组的未付发票。在一个月内创建但在月底前支付的发票不会显示在任何地方,但在 1 月 15 日创建并在 3 月 15 日支付的发票将包含在 2 月 1 日和 3 月 1 日列的总和中。
在 SSRS 中完成此任务的最佳方法是什么?
我无法找到原生 SSRS 解决方案,因此使用了循环几个月的存储过程:
@reportDate datetime,
@numberOfMonths int
DECLARE @results TABLE
(
ID int,
Column2 nvarchar(50),
Column3 nvarchar(50),
)
-- get the end of month values for each month
WHILE @numberOfMonths > 0
BEGIN
DECLARE @date datetime
SET @date = DATEADD(month, DATEDIFF(month, 0, @reportDate) - @numberOfMonths + 2, 0)
INSERT INTO @results
SELECT ID, Column1, Column2
FROM MyTable
WHERE ConditionToIncludeInThisPeriod
SET @numberOfMonths -= 1
END