Subject Building query strings in stored procedures?
Author willogibbo
I have a web application that is based on a Firebird 1.5 database.
Various pages contain grids of rows and columns taken from the
database. At the top of some columns I am providing filters with which
the user can choose single or multiple values on which to filter the
column.

Using something like PHP it is possible to build up an sql query
string to perform on the database, depending on what filters, how many
filters, and the values within the filters, the user chooses i.e.
resulting with a query string that contains various combinations of
(WHERE....OR...OR...) AND (... OR...OR...) etc..

What I would like to be able to do is replicate this within a stored
procedure (because there are other processes to perform on the
underlying data that are done by an SP and also I'm finding SPs
appreciably faster), but I am struggling to see how to go about it. In
the ordinary SQL aproach the filters and their values are handled as
arrays in building up the SQL statement. Can an array be inputs to an
SP and if so, how can arrays be handled within SPs?

I have achieved a part SP solution for which the number of possible
filters is known and each filter can have a single value only: this is
a layered tree structured...IF..NULL..ELSE.. approach etc. with single
value input parameters, but this is totally unwieldy and cannot
provide any managable flexibility.

Any thoughts on this very welcome. Thank you.