I have a page on my site which has multiple drop down boxes as filters.
So the SQL procedure for that page would be something like this
IF @Filter1 = 0, @Filter2 = 0, @Filter3 = 0
BEGIN
SELECT * FROM Table1
END
ELSE IF @Filter1 = 1, @Filter2 = 0, @Filter3 = 0
BEGIN
SELECT * FROM Table2
END
At the beginning, there were only a few results per filter so there weren't that many permutations. However, more filters have been added such that there are over 20 IF ELSE checks now.
So if each filter has 5 options, I will need to do 5*5*5 = 125 IF ELSE checks to return data dependent on the the filters.
Update The first filter alters the WHERE condition, the second filter adds more tables to the result set, the third filter alters the ORDER BY condition
How can I make this query more scalable such that I don't have to write a new bunch of IF ELSE statements to check for every condition everytime a new filter is added to the list besides using dynamic SQL...