In my MS SQL Server
database I am pulling transaction data based on a variety of different codes that are in one column.
Would it be more efficient to:
join the same table over and over for each code in a WHERE clause
do multiple case statements on the whole table (shown below)
do multiple case statements on the whole table but limit it by a
WHERE SubsidCde IN ('AA','BA','BB', etc)
clause
We have so many queries running per second that even though I have tried all 3 methods I get no definitive results.
SELECT
SUM(CASE WHEN Subsid_Cde = 'AA' THEN Trans_Amt END),0) [AA],
SUM(CASE WHEN Subsid_Cde = 'BA' THEN Trans_Amt END),0) [BA],
SUM(CASE WHEN Subsid_Cde = 'BB' THEN Trans_Amt END),0) [BB]
FROM
Transactions
-- There are 8 more rows like this, using a different code for each line