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 6709883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:56:05+00:00 2026-05-26T07:56:05+00:00

I have a telephones database table with 4 columns: countrycode areacode phonenumber extension I’m

  • 0

I have a telephones database table with 4 columns:

  • countrycode
  • areacode
  • phonenumber
  • extension

I’m following the “Canonical” formatting, since I have some international numbers to consider.

And as fate would have it, some numbers entered have extensions.

I have a query that I use to auto-format everything, except the extension:

SELECT CONCAT('+',`countrycode`,'(',`areacode`,')', `phonenumber`) AS `fullnumber` ... 

result: +1(123)4567890 or: +61(08)1234 1234
This works great, and it works perfectly with some dialer software I export to.

However, I now need to include the extension in this query. However, I need to auto-format it like so:

+1(123)4567890 x123

That’s rather easy, but since most numbers do not have an extension, I need to make a condition that will include the char (x). And this is my dilemma, since I’m still learning conditional statements in a query.

Anybody work with weird if/else statements inside a CONCAT?

  • 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-26T07:56:06+00:00Added an answer on May 26, 2026 at 7:56 am

    MySQL’s IF statement works like this:

    IF(condition, iftrue, iffalse): If the given condition is true, return the iftrue parameter. Otherwise, return the iffalse parameter.

    So, your query could look something like this:

    SELECT CONCAT('+',`countrycode`,'(',`areacode`,')', `phonenumber`, IF(`extension` IS NULL, "", CONCAT(" x", `extension`))) AS `fullnumber ...
    

    The MySQL IF function is one of several control flow functions. For more information on those functions, see the MySQL docs.

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

Sidebar

Related Questions

I have the following table which holds data on customers and staff. Would it
I have a database (SQL) with the table Staff with two records in it.
I have a Table that is generated using a SQL Database And put into
I have a simple database table (SQL Server 2008 R2 Express), which has a
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have this idea which I need some help with. Currently I am developing
so for my university coursework, i have to create an oracle database for an
I have problem when inserting a date to my database Insert query: INSERT INTO
We have a system that uses password authentication to access a database, the usernames
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote

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.