我正在尝试在 SSRS 报告中衡量和显示每周的增长。
我正在尝试结合使用 SQL 中的数据透视函数和参数来轻松检索我在 SQL 中需要的数据,而无需在 SSRS 中添加过于复杂的公式和矩阵。
我试过的公式是:
SELECT category, COALESCE (sum([@wedate]), 0) AS currentweek, COALESCE (sum([@wedate-7]), 0) AS previousweek
FROM OfficeProduction
PIVOT (sum(amount) FOR wedate IN ([@wedate], [@wedate-7])) AS p
WHERE category = 'Revenue'
GROUP BY category
当我尝试将其保存为存储过程时,我收到错误,以及当我将其直接插入 SSRS 中的数据集框时。
我已经测试了参数的插入值
SELECT category, COALESCE (sum([7/7/12]), 0) AS currentweek, COALESCE (sum([6/30/12]), 0) AS previousweek
FROM OfficeProduction
PIVOT (sum(amount) FOR wedate IN ([7/7/12], [6/30/12])) AS p
WHERE category = 'Revenue'
GROUP BY category
我得到了适当的结果......所以我感觉很接近,任何帮助将不胜感激。