I have 2 tables:
AppDetailFee table has AppID (PK), TypeID, Amount
AppDetail table has AppID (PK)
I join both tables on AppID and I need to check the following for TypeID and amount. There are 3 scenarios:
If TypeID = 6 and Amount = 0 then print appid and amount zero
If typeID = 6 and amount <> 0 - bypass and do not print
When TypeID <> 6 then print zero
Below is the code that I used, btu I get a result of all the rows that are not equal to zero with an amount of zero.
Any help would be appreciated.
Thanks
SELECT ad.AppID
, MAX(case when (adf.TypeID = 6 AND adf.Amount = 0) then 0
when (adf.TypeID = 6 AND adf.Amount <> 0) then Adf.Amount
ELSE 0 END) AS FeeAmount
FROM
AppDetail AS ad
inner join AppDetailFee adf ON
ad.AppID = adf.AppID
WHERE adf.Amount =0
You have a
WHEREclause that is removing everything that does not meet the criteria:Try removing that and running your query:
You are also missing the
GROUP BYclause on your query.