Full Name – get rid of the empty space if middle name is null
Posted on Monday, June 19, 2017
I see people bother with checking against NULL, using Coalesce, Substring etc. etc.
The solution is pretty simple actually. You just need to replace the two empty space by one if the middle name is null or empty e.g.
string fullName =
(reader["FirstName"].ToString() + " " +
reader["MiddleName"].ToString() + " " +
.Replace(" ", " ");
REPLACE(FirstName + ' ' + MiddleName + ' ' + LastName + ' ' + Suffix, ' ', ' ') AS FullName