Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:35:54+00:00 2026-06-18T02:35:54+00:00

I am using the substring function in a case statment to return all numbers

  • 0

I am using the substring function in a case statment to return all numbers between ‘B0’ – ‘B9’

WHEN SUBSTRING (postcode, 1, 2) like 'B[0-9]'

but i do not want to return the number ‘B5’ in this list. I can get it working as this

WHEN SUBSTRING (postcode, 1, 2) like 'B[0-4]'
WHEN SUBSTRING (postcode, 1, 2) like 'B[6-9]'

but is there a way to add this to one line like the following?

WHEN SUBSTRING (postcode, 1, 2) like 'B[0-9]' and not like 'B5'

EDIT:

how would you do this if you where dealing with numbers between 0-100 so the sql would be like

WHEN SUBSTRING (postcode, 1, 3) like 'B[0-9][0-9]'

but you did not want to include 16 and 17?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:35:55+00:00Added an answer on June 18, 2026 at 2:35 am
    WHEN SUBSTRING (postcode, 1, 2) like 'B[012346789]' -- No "5"
    

    LIKE patterns are awesome. Mini regex, if you will.

    To carry this out to the tens place or more for numbers, you might want to consider putting these values into a table that you can use for a join, exists or in.

    Or, since we’re treating the numeric portion of this column as though they were numbers and not a string, this is a sign that they might have been better stored as two columns: one for the alpha, one for the numeric.

    Barring any change to your schema, you might remove the alpha characters ad-hoc so you can compare them to a range of numbers, for example:

    where cast(replace(postcode, 'B', '') as int) between 0 and 15
        or cast(replace(postcode, 'B', '') as int) between 18 and 100
    
    where cast(right(postcode, len(postcode) - 1) as int) between 0 and 15
        or cast(right(postcode, len(postcode) - 1) as int) between 18 and 100
    

    These are just a couple of possibilities. You would know best how to massage your data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove substring out of variable using sed like this: PRINT_THIS=`echo
From a brief look using Reflector, it looks like String.Substring() allocates memory for each
I'd like to do a function which gets a string and in case it
getting error when i split the string using substring function in vb.net.it shows the
I'm getting an ArgumentOutOfRange error when using substring function in .NET. I'm new to
I have two tables. I need to join these tables using substring function. I
I have been using the following sort: var query = _cityRepository.GetAll( .OrderBy(item => item.RowKey.Substring(0,
At the moment I'm using all sorts of if statements and substrings in order
Using a populated Table Type as the source for a TSQL-Merge. I want to
I'm having a problem similar to jQuery $.ajax Not Working in IE8 but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.