Let's say I have two Oracle SQL queries that I'm using in various places in my code:
select *
from employees
where manager_id IS NULL
and etc etc etc...
and
select *
from employees
where manager_id IS NOT NULL
and etc etc etc...
The only difference between the two queries is that manager_id is NULL in the first one, and NOT NULL in the second one.
Is there any way to write this as one generic statement? Is it possible to pass in NULL or NOT NULL in a parameter? Something like this:
select *
from employees
where manager_id = ?
and etc etc etc...
I know the above example doesn't work (and I know why). My question is more along the lines of is there a more elegant solution than managing two separate SQL strings that are 99% similar?
manager_idnon-sargable. Also, the database would need to defend itself from ever getting this "special" value (e.g. through a CHECK).