I have to search for data across three columns. For certain users I search column 1, for other users I search column 1 and 3, and finally for other I look at column 2.
I know I could use a case or if statement and say if userId = 1 then
run a particular SQL statememnt. But the statement is pretty big, and I don't want to repeat the whole thing every time. Is it possible to use a CASE
or IF
statement (or something else) to change the conditions in the WHERE
part of the statement?
for example, if the company name is x check for value in column 1 or 3, otherwise check in column 2.
I've a very small SQL Fiddle here, but I've no idea where to begin.