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%'

  • 3
    Cant you use like '0560[0-9]%' ? This translates to 05601...9. Also, storing numbers as strings is not a good idea. – Kin Jan 17 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. – Michael Green Jan 18 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%' – Mike Jones Jan 18 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? – Michael Green Jan 24 at 10:54

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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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