Solved

SQL - how to conditional add space when append a string

Posted on 2012-04-04
2
475 Views
Last Modified: 2012-04-04
I have
a.[Name] + ' ' + a.[MiddleName] + ' ' + a.[SurName] As Name

This will create a string with one spacing between words

However when a.[MiddleName] is empty, I will have two spaces between Name and SurName.  How can I structure the above so there will be only a single space if MiddleName is empty
0
Comment
Question by:tommym121
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 37806430
Please try:

a.[Name] + ' ' + (case when a.[MiddleName] = '' then '' else a.[MiddleName] + ' ' end) + a.[SurName] As Name
0
 

Author Closing Comment

by:tommym121
ID: 37806461
Thanks.
0

Featured Post

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question