silverspecv
Programmer
I have a really slow query on a web page that I'd like to speed up. Basically, this search page accepts a list of product numbers and has to search a table where that value could be present in any of 8 fields, so the more products in the list, it gets very expensive, because it's using OR on 8 fields then 16 fields, then 24 fields, etc.. it is not uncoming to have 10 items in the list Right now I have it doing something like this.. Would this be a case for a stored procedure where I just pass it a list like ('asdf','qwer','zxcv') and it can do all the below faster?
I know it's ugly, but it's what I've got.. I've never used a stored procedure, so if that's the answer I'll learn it, but if there's some kind of case statement or some slick parameterization, that would be great.
Code:
select count(*)
from sales
where (1=0 or prod1='asdf' or prod2='asdf' or prod3='asdf')
or (1=0 or prod1='qwer' or prod2='qwer' or prod3='qwer')
or (1=0 or prod1='zxcv' or prod2='zxcv' or prod3='zxcv')
I know it's ugly, but it's what I've got.. I've never used a stored procedure, so if that's the answer I'll learn it, but if there's some kind of case statement or some slick parameterization, that would be great.