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
 Issue with a select query.

Author  Topic 

rowter
Yak Posting Veteran

76 Posts

Posted - 2011-03-16 : 12:20:29
Hi,

When i use the first query, i am getting the client names. But, when i use the second query i am getting only a few names.
For all the names which do not have a Middle Initial, i am not getting the client names?
MI column allows NULLS.
What is the difference and how to fix this issue?


This is working:
select (C.FirstNm + ' ' + C.LastNm ) AS ClientNm from clients as C

This is Failing. Returning only names which have MI(Middle Initial
select (C.FirstNm + ' ' + C.LastNm + ' ' + C.MI ) AS ClientNm from clients as C

Thanks in Advance

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-03-16 : 12:23:03
When you concatenate strings, NULL + string = NULL

select (C.FirstNm + ' ' + ISNULL(C.LastNm,'') + ' ' + C.MI ) AS ClientNm from clients as C

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

rowter
Yak Posting Veteran

76 Posts

Posted - 2011-03-16 : 12:26:50
jimf,

thanks that worked.
Go to Top of Page
   

- Advertisement -