1

In my WHERE clause, I'm trying to use LIKE for a range of numbers. For example:

WHERE rr.sequence LIKE '05600%' 
 OR rr.sequence LIKE '05601%' 
 OR rr.sequence LIKE '05602%' 
OR rr.sequence BETWEEN LIKE('056035%' AND '056038%')

Otherwise, I would need to use a LIKE statement for each potential number combination between '056035%' and '056038%'

Kin Shah
62.6k6 gold badges124 silver badges247 bronze badges
asked Jan 17, 2019 at 21:28
4
  • 3
    Cant you use like '0560[0-9]%' ? This translates to 05601...9. Also, storing numbers as strings is not a good idea. Commented Jan 17, 2019 at 21:37
  • Check the length of these number-strings as '05600%' will match '056001' and also '05600999999999999'. To wit an actual CHECK may be appropriate. Commented Jan 18, 2019 at 1:58
  • Upon further review, you're exactly right. How else would I go about filtering the Sequence range that includes: '0560%' thru '05608985%' Commented Jan 18, 2019 at 22:49
  • Will these values all have the same number of digits? On other words, if they were all actual numbers instead of numbers-as-strings, would they all be of the same order of magnitude? Are there any business rules saying what the lower and upper values in any search could be? Commented Jan 24, 2019 at 10:54

1 Answer 1

1

It looks like you need to do the following:

OR rr.sequence LIKE '05603[5-8]%'

But in general, I agree with Kin's comment on the question: "storing numbers as strings is not a good idea".

answered Jan 17, 2019 at 22:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.