How to ignore the condition that user did not pass in SQLITE?

I am doing my crm project with SQLITE+FLASK. And I need a feature is let user to input the condition to filer the result.

I hope that my SQL statement can ignore the WHERE condition if the parameter is space or null.

For example, My input is "NAME", "AGE", "GENDER" so my statement will be

SELECT *
FROM CUSTOMER
WHERE NAME = 'James' AND AGE = '25' AND GENDER = 'M'

But I hope that if user did not enter "NAME" my SQL statement can be something like the code below

SELECT *
FROM CUSTOMER
WHERE AGE = '25' AND GENDER = 'M'

I know maybe I can do this with string concat, but I hope I can do this by SQL statement.



Read more here: https://stackoverflow.com/questions/65702995/how-to-ignore-the-condition-that-user-did-not-pass-in-sqlite

Content Attribution

This content was originally published by EnergyBoy at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: