Unanswered: Conditional condition - is it possible?
I'm probably overlooking something really simple (and I've tried searching first) but I can't seem to create a WHERE condition that depends on whether another condition is true or false. In other words, if a.col1 = '1' then select where b.col1 <> 0, or something to that effect. Here's what I've tried so far:
--IF HAN.KOMK_1 = '1' THEN WHERE UDR.TNK_MRK = 'J' ELSE
WHERE UDR.TNK_MRK = '%' END IF
--WHERE IF HAN.KOMK_1 = '1' THEN UDR.TNK_MRK = 'J' ELSE
UDR.TNK_MRK = '%' END IF
--WHERE UDR.TNK_MRK LIKE (IF HAN.KOMK_1 = '1' THEN 'J'
ELSE '%' END IF)
--WHERE UDR.TNK_MRK LIKE (CASE WHEN HAN.KOMK_1='1' THEN
'J' ELSE '%' END)
--WHERE UDR.TNK_MRK (CASE WHEN HAN.KOMK_1='1' THEN LIKE
'J' ELSE LIKE '%' END)
--WHERE (CASE WHEN HAN.KOMK_1='1' THEN UDR.TNK_MRK LIKE
'J' ELSE UDR.TNK_MRK LIKE '%' END)
WHERE (CASE WHEN HAN.KOMK_1='1' THEN UDR.TNK_MRK ELSE UDR.HANTEI END)
The commented out lines are my attempts that produced errors and the final line works but does not produce the result I'm after.
I originally had this done in Java looping through each record but was told it had to be in SQL as around 6-8 millions records are being summed. Seems like a fair request but it's too much for my grey matter. Can anyone help?
Thank you in advance.