stored procedures - How to handle complex conditional where clauses in mysql -
based on variety of optional user inputs, need modify structure of clause in query (not dynamic values, dynamic structure).
examples.. if select customerid, don't use branchid filter, if select empid use both empid , branchid filters. there more criteria used well, thats example.
i could build logic clause using case statements, i'm guessing wouldn't optimized? know dynamically build sql statement within stored proc, , use prepared statements well... seems sloppy? there method i'm not thinking of?
the usual approach dynamically building query in layer handles user input. in case not use high level language in front of database, means resorting stored procedure indeed, , might bit dirty indeed - find language quite awkward.
a pure sql solution not have of overhead, since constant-based conditions optimized away quite efficiently (user input constant when query starts).
Comments
Post a Comment