Print Thread
TOracleQuery with NULL variables
#48607 02/16/14 02:15 PM
Joined: Mar 2013
Posts: 8
N
nrsgzz Offline OP
Member
OP Offline
Member
N
Joined: Mar 2013
Posts: 8
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?

Re: TOracleQuery with NULL variables
nrsgzz #48611 02/17/14 11:33 AM
Joined: Aug 1999
Posts: 22,204
Member
Offline
Member
Joined: Aug 1999
Posts: 22,204
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))


Marco Kalter
Allround Automations

Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.067s Queries: 15 (0.007s) Memory: 2.4977 MB (Peak: 3.0398 MB) Data Comp: Off Server Time: 2024-04-25 23:11:49 UTC
Valid HTML 5 and Valid CSS