I would like to have a query that uses a larger number of two values / columns if a different value is true for the record.
I am trying to get accounts in reports. Unfortunately, the database usually stores the Cash value in a column called HoldingQty , while for every other type of holding (stocks, bonds, mutual funds) it stores it in the Qty column.
The problem is that sometimes the value of funds is stored only in Qty , and sometimes in Qty and HoldingQty . Obviously, sometimes it is stored only in HoldingQty , as mentioned above.
Basically, I want my select statement to say: "If security is money, look at qty and hold qty and give me a value of whichever is greater. Otherwise, if security is not money, just give me qty" .
How can I write this in T-SQL? Here are my efforts:
SELECT h.account_name, h.security_name, h.security_type, h.price, (CASE: WHEN security_type = 'cash' THEN (WHEN h.qty > h.holdingqty THEN h.qty ELSE h.holdingqty) ELSE qty) as quantity, h.total_value FROM holdings h WHERE ...........
source share