Posted By: nrsgzz TOracleQuery with NULL variables - 02/16/14 02:15 PM
Hi all.
I have a query that uses variables, something like this

SQL Query
SELECT *
FROM
MYTAB A
WHERE
A.COL1 = :COL1
AND
A.COL2 = :COL2

However the variables could be null and in that case the query will never return any results.
How can I make it work?
Posted By: Marco Kalter Re: TOracleQuery with NULL variables - 02/17/14 11:33 AM
Comparing with NULL will resolve to NULL, which is neither True nor False.

You can change the query as follows:
Code
SELECT *
FROM
MYTAB A
WHERE
(A.COL1 = :COL1 OR (A.COL1 IS NULL AND :COL1 IS NULL))
AND
(A.COL2 = :COL2 OR (A.COL2 IS NULL AND :COL2 IS NULL))
© Allround Automations forums