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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:33:53+00:00 2026-06-13T04:33:53+00:00

I have the following syntax on my SELECT Statement: CONCAT(first_name, , COALESCE(middle_initial), , last_name)

  • 0

I have the following syntax on my SELECT Statement:

CONCAT(first_name, " ", COALESCE(middle_initial), " ", last_name) AS full_name

Obviously, what I get is the following:

For first_name='John' and middle_initial='A.' and last_name='Smith' 
I get 'John A. Smith'

That is fine and is the desired result.

But I get an extra space for the following data (which I clearly understand why):

For first_name='John' and middle_initial='' and last_name='Smith' 
I get 'John  Smith'

Is there a way with COALESCE() to append ” ” if the condition returns a non-null value?

Thank you.

  • 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-13T04:33:54+00:00Added an answer on June 13, 2026 at 4:33 am

    When middle_initial has ”, you would want to:

    SELECT CONCAT(first_name, ' ', 
       CASE
          WHEN middle_initial is null OR middle_initial = '' then ''
          ELSE CONCAT(middle_initial, ' ')
       END
       , last_name) AS full_name
    

    SQLFiddle Example

    COALESCE is used for checking NULL values, not handling empty strings, ”

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

Sidebar

Related Questions

I have an MS SQL function that is called with the following syntax: SELECT
I have following syntax in my script to get email address from string. The
I have the following select statement where I need to sum each task from
I have a case expression in a DB2 statement like the following. SELECT A,
I'm new to conditional statements within postgres. I have the following statement SELECT IF
I have the following SQL statement SELECT be.*, it.order_number FROM songs AS be INNER
I have the following SQL statement: WITH CTE(Col01,...,Col05) AS ( ... ) SELECT ....
I have a query with the following syntax: select x.a as a, x.b as
I have the following SQL statement sample: SELECT DISTINCT [CommentNdx] ,[CommentsText] ,[DateTimeAdded] FROM [dbo].[CommentTable]
I have the following syntax in the .cmd file, where PathList is console application

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.