I am having issues with this wildcard lookup, not sure why this doesn't work:
I am looking up example Sales Agent 42. As you can imagine being sales, they do not really care about garbage in = garbage out. So their agent codes are usually a mess to sort through.
Valid Examples for Agent 42:
- 42
- 30-42-22-holiday
- 42easter
- 42-coupon
- 42coupon-423355
- 29-42sale-52
Non-Valid Examples that explicitly need to not show up
- A4290042
- 4297901
- 42cmowc209d
- o203f9j42po0
Here is the most successful model I came up with:
SELECT company_id, agent
FROM cust_data
WHERE (agent = ('42') OR agent LIKE ('42%-%') OR agent LIKE ('%-%42') OR agent LIKE ('%-%42%-%') OR agent LIKE ('42[a-z]%-%') OR agent LIKE ('%-%42[a-z]%') OR agent LIKE ('%-%42[a-z]%-%') OR agent LIKE ('42[a-z]%'))
I get most of the valid ones to return and none of the non-valid ones, but I still can't seem to grab the examples like 42easter or 29-42sale-52 even though I am telling it to grab that style...
Any suggestions?