I have an asp.net page that allows a user to search the database by generating the where clause to include in a stored procedure. The issue is that the procedure has to allow for a unknown number of parameters for varying conditions. An overly simplified example could look something like:
SELECT [Column1] FROM [TableName] WHERE 1=1
--Everything below user generated
AND
(
([Column2] = '1' AND [Column3] = '5' AND [Column4] = '9') OR
([Column2] = '2' AND [Column3] = '6' AND [Column4] = '8') OR
...
([Column2] = '25' AND [Column3] = '3' AND [Column4] = '1')
)
AND [Column5] BETWEEN '10' AND '200'
I was wondering what the best solution for this would be. I know that I can build the where clause as a string and pass it to the stored procedure as one big parameter, and execute the lot as dynamic sql, but what would be a better solution?