Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

How to omit the middle column in case of a null value while displaying three columns as a concacted single column

$
0
0
Hey guys, I am new to SQL and was wondering if anyone can help me with a question. Listing the full names is easy with Aliases but I do not know how to omit the middle column in case of no middle initial. Can anyone please explain how to get that done for the following question please?

List the full names of all employees in the format similar to “Alfred T. Pennyworth”. If they do not have a middle initial, omit the initial and have a space only

For an employee table in Pubs database with three different columns holding the First name, Middle Initial and Last names, I am supposed to display them in the format of “Alfred T. Pennyworth”. However, in case the middle initial column has no data, it has to omit the data and skip the column completely and display first name and middle name as “Alfred Pennyworth”.   How is this possible?

I did the following but it still has the ".'' after the first name even in case of no middle initial and that's not desirable. I need to have the syntax omit the whole middle initial column in case it has a null value.

select 
[fname]+' '+[minit]+'.'+' '+[lname] as fullname
from [dbo].[employee]

Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>