How to use IS NULL in a parameterized query (Delphi)

I have received such statements:

SELECT * From Table WHERE Feld IS NULL
SELECT * From Table WHERE Feld IS NOT NULL

Now I am wondering how I can parameterize this query:

SELECT * From Table WHERE Feld IS :Value

Since I cannot use the "NOT NULL" parameter for the parameter, I think this is not possible at all, but maybe someone knows a solution for this? Thank!

+5
source share
1 answer

You can try something like this (tested with Firebird 2.5):

SELECT * FROM TABLE WHERE (IIF(FIELD IS NULL, 'Y', 'N') = :IS_NULL)

then pass 'Y'or 'N'to the parameter IS_NULL.

Depending on the database you are using, you may need to replace it IIFwith CASEor a similar design.

+6
source

All Articles