0

I have table with a string field ID with values looking like this:

 012345678

I want to select all the records from the ID field that begin with a 0 and have a letter in them, e.g 000A345B or 0A32C450. I also want to select records that begin with zero and contain a -, / or a space.

Note that records should begin with 0.

How do I resolve this?

0

1 Answer 1

10

You can catch any starting with 0 and having a letter in it using

WHERE ID LIKE '0%[A-Z]%'

You can catch any starting with 0 and having the characters 'A', '-', or '/' in them using

WHERE ID LIKE '0%[-A/]%'

You can also combine an explicit list and a range in one expression. You just need to remember that if the list includes a -, you need to specify it first, then list other characters and/or character ranges. To match all your requirements, for example, the predicate would look like this:

WHERE ID LIKE '0%[- /A-Z]%'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.