I am trying to return only those grouped rows where the OriginalAmt does not equal the ReverseAmt. Instead of the query giving me the rows I want, it returns all rows.
Please help. Need ASAP.
I also tried:
Michael Libeson
Please help. Need ASAP.
Code:
SELECT h.Account, h.ApplSeq,
SUM(CASE WHEN h.Dcindicator = 0 THEN h.Tramt ELSE 0.0 END) AS 'OriginalAmt',
SUM(CASE WHEN h.Dcindicator = 1 THEN h.Tramt ELSE 0.0 END) AS 'ReverseAmt',
(SELECT SUM(Tramt) FROM THistory x WITH (NOLOCK) WHERE x.Account = h.Account AND x.ApplSeq = h.ApplSeq AND dbo.fn_GetTranxCodeCPA(x.Trntype) = 'P' AND x.Trncode LIKE 'TBI[PST]') AS 'TBI_AMT'
FROM THistory h WITH (NOLOCK)
WHERE h.Trncode = 'RLNS'
AND h.dtePosted_Date >= CAST('01/01/2009' AS DATETIME)
AND EXISTS(SELECT * FROM THisIns i WHERE i.Account = h.Account AND i.ApplSeq = h.ApplSeq AND i.Inscode = 'BCFP')
GROUP BY h.Account, h.ApplSeq
HAVING SUM(CASE WHEN h.Dcindicator = 0 THEN h.Tramt ELSE 0.0 END) <> SUM(CASE WHEN h.Dcindicator = 1 THEN h.Tramt ELSE 0.0 END)
ORDER BY 1, 2;
I also tried:
Code:
HAVING 'OriginalAmt' <> 'ReverseAmt'
Michael Libeson