Efficient Way to Select if a database row value match a group of string
SELECT id FROM tablename where
LeadStatus like "%Contact Attempt 1%" or
LeadStatus like "%Contact Attempt 2%" or
LeadStatus like "%Contact Attempt 3%" or
LeadStatus like "%Contact Attempt 4%" or
LeadStatus like "%Contact Attempt 5%" or
LeadStatus like "%Contact Attempt 6%" or
LeadStatus like "%Contact Attempt 7%" or
LeadStatus like "%Call Back/Follow-up%" or
LeadStatus like "%Working%" or
LeadStatus like "%Credit Pulled%" or
LeadStatus like "%Selected other Lender%" or
LeadStatus like "%Pre-Approved%" or
LeadStatus like "%Application Taken/Sent%" or
LeadStatus like "%Application Received%" or
LeadStatus like "%Submitted%" or
LeadStatus like "%Funded%" or
LeadStatus like "%Future Opportunity%" or
LeadStatus like "%Manager Review%"
I think it clear enough that what I want?
Note : I can’t change the LeadStatus value as it is fetched from a API not in my control
How about using the IN operator?
Here’s an example at SQLFiddle.com.
You can build out the CSV list of strings dynamically & just insert it in between the parenthesis. The only drawback to using the IN operator though is that you cannot apply wild card searches (with the “%”).