I am using the following code and am looking to have column Total_Bank_Amount
and Prog_Variance
SUMed from the SUMs in the previous CASEs.
SELECT
b.Date,
SUM(p.Prog_Amount) AS Prog_Amount,
SUM(o.Credit_Amt) AS Outstanding,
CASE
WHEN b.Bank_Name Like '%Corp%'
THEN SUM(b.Credit_Amt)
END AS TMP_Amount,
CASE
WHEN b.Bank_Name Like '%Cleo%'
THEN SUM(b.Credit_Amt)
END AS Cleo_Amount,
CASE
WHEN b.Bank_Name Like '%NY Bank%'
THEN SUM(b.Credit_Amt)
END AS NY_Amount,
CASE
WHEN b.Bank_Name Like '%MA%'
THEN SUM(b.Credit_Amt)
END AS MA_Amount,
CASE
WHEN b.Bank_Name Like '%CT%'
THEN SUM(b.Credit_Amt)
END AS CT_Amount,
CASE
WHEN b.Bank_Name Like '%NY_SS%'
THEN SUM(b.Credit_Amt)
END AS NY_SS_Amount,
CASE
WHEN b.Bank_Name LIKE '%VC_SS%'
THEN SUM(b.Credit_Amt)
END AS VC_SS_Amount,
(TMP_Amount + Cleo_Amount + NY_Amount + MA_Amount + CT_Amount + NY_SS_Amount + VC_SS_Amount) AS Total_Bank_Amount,
(Prog_Amount + Outstanding - TMP_Amount - Cleo_Amount - NY_Amount - MA_Amount - CT_Amount - NY_SS_Amount - VC_SS_Amount) AS Prog_Variance
FROM
vw_Prog_Reference_Summary p
RIGHT JOIN
Bank_Detail b ON p.Bank_Reference_Number = b.Bank_Reference
LEFT JOIN
vw_Outstanding_Form o ON b.Bank_Reference = o.Bank_Reference
LEFT JOIN
Exclusion e ON b.Bank_Reference = e.Exclude
WHERE
e.Exclude IS NULL
GROUP BY
b.Bank_Name, b.Date
The issue is that these are not created by the time they parse so how do you get around this? Research has me coming up with nothing =(. Thanks.