SQLite Forum

SELECT optimization for constant expression
Login
Try reformulating your statement using CASE for the conditional decisions:

~~~
SELECT * FROM person
WHERE case when ?1 NOT NULL then firstname  LIKE ?1 else 1 end
  AND case when ?2 NOT NULL then lastname   LIKE ?2 else 1 end
  AND case when ?3 NOT NULL then birthdate   ==  ?3 else 1 end
  AND case when ?4 NOT NULL then maidenname LIKE ?4 else 1 end
ORDER BY lastname, firstname;
~~~