Thursday, 15 May 2014

stored procedures - How to handle complex conditional where clauses in mysql -


Based on many alternate user inputs, I need to modify the structure of the query where the query (not just dynamic Values, but dynamic structure). Example: If they select the customer ID, do not use the branch ID filter, but if they select an empID, then use both empID and branchID filters, plus more criteria There are also, which is just an example .

I may have be made creating all the arguments in the section using the CASE statements, but I feel that it will not be very well adapted? I know that I can dynamically create the sql statement within a stored proc, and I can also use the prepared statement ... but it looks sloppy? Is there any other way that I am thinking?

The general approach is to dynamically create a query layer which handles user input if you have your database Do not use a high level language in front of it, it means that in fact one should resort to a stored procedure and it can actually look a little dirty - I find this language very strange.

A pure SQL solution does not have too much overhead, since static-based conditions can be optimized very efficiently (user input is stable when query starts).


No comments:

Post a Comment