- Original expression
SELECT FirstName + ' ' + LastName + ' '+ ISNULL(MI + '.', '') As MiddleInitial FROM CS_tblMaster WHERE CustomerNo = 2627240
- My original answer (edited)
SELECT FirstName + ' ' + LastName + ' '+ (ISNULL(MI, '') + '.') As MiddleInitial FROM CS_tblMaster WHERE CustomerNo = 2627240
In this case, SQL will first check if MI is Null and use MI if Not Null, or use an empty string if it is. He then combines this result, which is now Null, with the period.
- Final answer
SELECT FirstName + ' ' + LastName + ' ' + CASE WHEN MI IS NULL THEN '' ELSE MI + '.' END As MiddleInitial FROM CS_tblMaster WHERE CustomerNo = 2627240
@Satish, not sure if you feel that you have an answer since you didn’t choose it, and I apologize if my answer was short and quick. Having seen all the answers, I realized that I did not think about your question when I first saw it.
To answer “I would like to understand this implementation,” Nulls is a very special meaning in SQL. Not an empty string, not spaces, not zeros. They literally mean "nothing." You can check them out if this can be something empty. But you cannot do things with Nulls. So 57 + Null = Null. 'Mary' + Null = Null. ((12 * 37) +568) / Null = Null. Max () “Albert”, “Maria”, “Zero” and “Zek” are “Zero”. This article http://en.wikipedia.org/wiki/Null_(SQL) can help with a decent description in the Null Propagation section.
The Isnull function is not so much a test for Null as a processing method. Therefore, to check if something is Null, you should use ColumnName Is Null or ColumnName, not Null in your Select. What Isnull (MI, ``) says: I want a value, if the MI value is not null, then I want MI, otherwise I want an empty string.
Continuing, I'm not sure I initially understood what you were actually trying to do. If you tried to get a period when the average starting number was zero, then my original answer and most others will work for you. But I think you are probably trying to say: “If I have an average starting level, then I need an average starting period, followed by a period. If I don’t have an average starting level, I don’t want anything: Alberto S. Santaballa "Alberto Santaballa, never Alberto. Santaballa." If so, then use the final report in the edited answer.
@Zec, thanks for editing. A typo was another product of typing too fast !: - /