Not sure what your database is as you did not tell us, but it it does allow stored procedures then the most efficient way is to create a stored procedure containing a structure of IFs and a separate SELECT for each combination. That way the server can prepare and store execution plans for each of the cases. You of course do not have to write all those selects by hand, you can generate them
If the SELECTs are more complex or involve complex views then you can save the database server a lot of work regenerating the execution plan.IF (@Name is NULL) IF (@Address is NULL) IF (@Email is NULL) SELECT ... FROM TheTable ELSE SELECT ... FROM TheTable WHERE Email like @Email + '%' ELSE ...
In reply to Re: Build SQL on the fly from WEB search form
by Jenda
in thread Build SQL on the fly from WEB search form
by data67
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |