我正在使用SSRS和SSMS 2008 R2。我有2個報告,用戶想要合併爲1個報告,並選擇 日期以獲取2013或2014年的數據。兩個報告中的所有數據集都是相同的,每個報告中有一個 數據集具有不同硬編碼Where Where子句2013組與2014年客戶羣的價值。 我以爲我可以在Where子句中選擇CASE語句來選擇基於@Startdate參數的硬編碼2013組或2014組,但這不起作用,關於如何執行此操作的任何想法?如何編碼Where子句以根據參數選擇傳遞數據
這裏是2013查詢和2014年查詢的WHERE子句的2份報告之間的唯一區別:
SELECT [FISCAL YEAR]
,COUNT(*) AS EXPECTED
,SUM(Amount) AS Total
FROM dbo.Table1 T1
INNER JOIN dbo.Table2 T2
ON T1.primarykey = T2.primarykey
WHERE Field1 IN (
5555
,6666
)
AND Field2 IN (
2222
,3333
)
AND YEAR(T1.DATE) = YEAR(@StartDate)
AND T1.AMOUNT >= 25000
AND T1.DESCRIPTION IN (
'The Campaign - YYY - 2011-2015'
,'The Campaign - ZZZ - 2011-2015'
,'2013 AAA Goal'
,'2013 BBB Goal'
,'2013 CCC Goal'
,'2013 DDD Goal'
,'2013 EEE'
,'2013 FFF'
)
GROUP BY RIGHT(CONVERT(VARCHAR, T1.DATE, 1), 2)
SELECT [FISCAL YEAR]
,COUNT(*) AS EXPECTED
,SUM(Amount) AS Total
FROM dbo.Table1 T1
INNER JOIN dbo.Table2 T2
ON T1.primarykey = T2.primarykey
WHERE Field1 IN (
5555
,6666
)
AND Field2 IN (
2222
,3333
)
AND YEAR(T1.DATE) = YEAR(@StartDate)
AND T1.AMOUNT >= 25000
AND T1.DESCRIPTION IN (
'The Campaign - YYY - 2011-2015'
,'The Campaign - ZZZ - 2011-2015'
,'2014 AAA Goal'
,'2014 BBB Goal'
,'2014 CCC Goal'
,'2014 DDD Goal'
,'2014 EEE'
,'2014 FFF'
,'2014 GGG'
,'2014 HHH'
,'2014 JJJ'
,'2014 LLL'
)
GROUP BY RIGHT(CONVERT(VARCHAR, T1.DATE, 1), 2)
任何想法鄉親? – DataDude