I have a form that is going to be used to search through a table of support tickets.
the user can search from a few difficult optional fields.
- Date (to/from)
- Ticket Status
- Engineer
- Ticket Contact
I’m wondering what is the best way to deal with optional search filters. So I have a query that takes in parameters from the user. So if the user searches using both the from and to dates then the query would want to include BETWEEN. So do I have to write a different query for if the user searches for only from. or another query when the user has not added any date parameters? Then what if the status dropdown is blank? Is that another query?
Any help to clear this up would be great!
Jonesy
Build your query in parts. Start with whatever is constant in your query, and add on more SQL depending on what extra conditions:
This code is obviously just a skeleton, but that’s how I would construct my query.