一個Policy Number
可以有多個不同的ClassCode
只有一個Premium
總量。在我的SSRS報告中,我希望能夠創建參數ClassCode
,並且如果我排除(取消選中)至少其中一個ClassCode
,則具有Premium的整個保單號碼不需要計算在內。 可以說,如果我想排除ClassCode 58
,那麼1,644.00的Premium
不應該在我的報告結果中。如何排除一個價值,並具有該值不被計算在一切
我想在我的查詢AND ClassCode <> 58
說,但它只是排除了一行,並保持高級anount。但我的目標是要排除一切,如果它有ClassCode 58
SELECT policynumber,
classcode,
/*
Using ROW_NUMBER() to check if it's the first record in the join and returns the Premium value if so, otherwise it will display 0.
The ORDER BY (SELECT 0) is there just because I don't need the row number to be based on any explicit order.
*/
CASE
WHEN ROW_NUMBER()
OVER (
PARTITION BY cte1.policynumber
ORDER BY (SELECT 0)) = 1 THEN premium
ELSE 0
END AS Premium,
c.yearnum TransEffYearNum,
c.monthnum TransEffMonthNum
FROM cte1
INNER JOIN cte2
ON cte1.policynumber = cte2.policynumber
RIGHT JOIN tblcalendar c
ON c.yearnum = Year(cte1.policyeffectivedate)
AND c.monthnum = Month(cte1.policyeffectivedate)
WHERE c.yearnum = 2016
AND classcode <> 58
ClassCode屬於哪個表? – DVT
在我的查詢中,ClassCode屬於'cte2'。我只在這裏顯示最終的'SELECT'語句。導致相當長的查詢。 – Oleg
因此,對於您的問題的示例,您想要完全取消策略3,還是隻想將ClassCode 57的Premium升級爲0? – DVT