SQL query which will ignore null parameters
Posted on 2003-03-04
I need to write a query which will run a check on a number of fields based on parameters passed in at run time.
if a parameter to check against a field is left null, I want the query to skip the check against that particular field, hence only querying on the fields for which parameters have been entered.
if I had:
select * from customers
where name = :param1
age = :param2
surname = :param3
and I gave it the parameters:
it would only search on the name and surname fields in the customers table.