- Moderator
- #1
I have written a little web page that searches through our accounting database.
It takes about 7 seconds to search through a few hundred thousand records, and the reason is because it is using multiple OR's with LIKE's.
So, for example, the query looks similar to this:
SELECT * FROM AccountingDatabase WHERE BillToName LIKE '%@Search%' OR ShipToName LIKE '%@Search%' OR BillToZip = @Search OR ShipToZip LIKE '%@search%' OR CustomerPhone = @Search OR BillToCity LIKE '%@Search%' OR OrderNumber = @Search
... and so on.
So, what would be the "correct" way to do this? I thought about concatenating another field with all of the fields that I am doing LIKE searches on, so I can do a LIKE search just on that one field...
Not all of the criteria are LIKE's... for example, and order number would be an exact match.
This is proving to be a really useful tool, allowing us to type the criteria into one box, and have it search a whole bunch of fields. However, it's time to optimize it for speed.
Thoughts? Comments? Thank you in advance!
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg
It takes about 7 seconds to search through a few hundred thousand records, and the reason is because it is using multiple OR's with LIKE's.
So, for example, the query looks similar to this:
SELECT * FROM AccountingDatabase WHERE BillToName LIKE '%@Search%' OR ShipToName LIKE '%@Search%' OR BillToZip = @Search OR ShipToZip LIKE '%@search%' OR CustomerPhone = @Search OR BillToCity LIKE '%@Search%' OR OrderNumber = @Search
... and so on.
So, what would be the "correct" way to do this? I thought about concatenating another field with all of the fields that I am doing LIKE searches on, so I can do a LIKE search just on that one field...
Not all of the criteria are LIKE's... for example, and order number would be an exact match.
This is proving to be a really useful tool, allowing us to type the criteria into one box, and have it search a whole bunch of fields. However, it's time to optimize it for speed.
Thoughts? Comments? Thank you in advance!
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg