I have a varchar field in a SQL Server database that stores phone numbers in many different ways, but they are all phone number essentially.
Examples:
8181234564
(818) 123 4564
818 - 123 - 4567
I was hoping I can use regex to strip out all non-numeric characters and then perform a like or “=” on .. can I do that?
forgot to mention: I only have read access.
If you know that the field contains a phone number in some kind of valid form, then the following really ugly usage of LIKE would match a specific number. To find 818-123-4567:
This, of course, would match invalid entries as well (e.g., numbers that had extra digits, characters, etc.). And it would likely be a fairly expensive query unable to use any indexes.
A more realistic version might be this: