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

  • Home
  • SEARCH
  • 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 745581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:35:59+00:00 2026-05-14T09:35:59+00:00

I’ve got a wonderfully fun little SQL problem to solve today and thought I’d

  • 0

I’ve got a wonderfully fun little SQL problem to solve today and thought I’d ask the community to see what solutions you come up with.

We’ve got a really cool email to text service that we use, you just need to send an email to phonenumber@servicename.com and it will send a text message to the desired phone number.

For example to send a text to 0790 0006006, you need to send an email to 07900006006@servicename.com, pretty neat huh?

The problem is with the phone numbers in our database. Most of the phone numbers are fine, but some of them have “rubbish” mixed in with the phone number.

Take these wonderful examples of the rubbish you need to deal with (I’ve anonymised the phone numbers by placing zeroes in):

07800 000647(mobile)
07500 000189 USE 1ST
SEE NOTES
07900 000415 HO ONLY
try 1st 0770 0000694 then home
07500 000465 Cannot

Requirements

The solution needs to be in SQL (for MS SQL server).

So the challenge is as follows, we need to get the phone number without spaces, and without any of the rubbish seen in the samples.

For example:

This:

try 1st 0770 0000694 then home

Should become this:

07700000694

Anything without a phone number in it (e.g. “SEE NOTES”) should be null.

UPDATE:

Thanks for the great responses! We’ve had some interesting answers, but seeing as none of the SQL answers have had any votes it’s a bit hard to pick a favourite. I’d have rather seen a clear favourite picked by the community.

I’ll let the question mature a little more and see if any votes come in before I award an answer.

  • 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-05-14T09:36:00+00:00Added an answer on May 14, 2026 at 9:36 am

    Assuming that yopur phones always start with ’07’ and the length is 12 characters you can try something like this:

    DECLARE @Number varchar(50)
    
    --SET @Number='07800 000647(mobile)'
    --SET @Number='07500 000189 USE 1ST'
    --SET @Number='SEE NOTES'
    --SET @Number='07900 000415 HO ONLY'
    --SET @Number='try 1st 0770 0000694 then home'
    SET @Number='07500 000465 Cannot '
    
    
    
    SELECT REPLACE(SUBSTRING(@Number, case when CHARINDEX ('07',@Number ) =0 then Null 
    else CHARINDEX ('07',@Number )end , 12),' ','')
    

    First of all, finding the starting point of the ’07’ string, then, if it is 0 (‘SEE NOTES’), return Null. After that, getting the 12 characters of the number.
    Lastly, replacing the spaces…

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

Sidebar

Ask A Question

Stats

  • Questions 389k
  • Answers 389k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Lots of points: no need for IIS - this can… May 15, 2026 at 12:45 am
  • Editorial Team
    Editorial Team added an answer You could use a color or an image. You can… May 15, 2026 at 12:45 am
  • Editorial Team
    Editorial Team added an answer First, you must close the <library> tag, otherwise the XML… May 15, 2026 at 12:45 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.