I’m working on an application for work that is going to query our employee database. The end users want the ability to search based on the standard name/department criteria, but they also want the flexibility to query for all people with the first name of ‘James’ that works in the Health Department. The one thing I want to avoid is to simply have the stored procedure take a list of parameters and generate a SQL statement to execute, since that would open doors to SQL injection at an internal level.
Can this be done?
While the
COALESCEtrick is neat, my preferred method is:These kind of SPs can easily be code generated (and re-generated for table-changes).
You have a few options for handling numbers – depending if you want exact semantics or search semantics.