Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Retrieve firstname, lastname, MI as fullname

Author  Topic 

rowter
Yak Posting Veteran

76 Posts

Posted - 2009-11-30 : 11:00:23
Hi,

I need to display the first name, last name and MI together as fullname. Not all the names have Middle Initials.

I am using this query to get all the names without MI.
Select Lastnm + ' ' + FirstNm as fullname from clients

If i include MI i am able to see only names which have MI . Is there any query which displays the names whether or not the MI exists?
Select Lastnm + ' ' + FirstNm + ' ' + MI as fullname from clients

Thanks in Advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-30 : 11:01:46
[code]Select Lastnm + ' ' + FirstNm + coalesce(' ' + MI,'') as fullname from clients[/code]
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-30 : 11:03:07
SET CONCAT_NULL_YIELDS_NULL OFF;

Select Lastnm + ' ' + FirstNm + ' ' + MI as fullname
from clients

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

rowter
Yak Posting Veteran

76 Posts

Posted - 2009-11-30 : 11:24:44
Thanks Visakh16 and tkizer.
It worked both ways.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-30 : 12:22:54
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -