Hi All
I am facing a issue in applying a conditional 'if' in the where clause of the SQL query.
Here is the query. I have removed the unnecessary joins, columns names and multiple conditions in WHERE clause to make it readable.
SELECT TransactionId, TransactionDate , ProcessingDate FROM TransactionDetails
WHERE TransactionId in (2,3,9) AND ...AND ..
Now, I need to select the records from the TransactionDetails table with another transaction Ids 14 & 15 ONLY if the TransactionDate <> ProcessingDate for that particualr record.
What I tried:
Tried using IF ELSE - but it worked only with the variables. I want to apply the condition on the Dates columns from the table.
select * from transactionDetails
WHERE OrderID in (400376, 400379)
AND
IF TransactionDate <> ProcessingDate
TransactionId in (2,3,9,14,15)
ELSE
TransactionId in (2,3,9)
I get two errors as -
Incorrect syntax near the keyword 'IF'.
Incorrect syntax near 'TransactionId'.
Please comment if you want me to improve my question