Full Name – get rid of the empty space if middle name is null
by Yugolancer
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.
C#
string fullName =
(reader["FirstName"].ToString() + " " +
reader["MiddleName"].ToString() + " " +
reader["LastName"].ToString())
.Replace(" ", " ");
T-SQL
REPLACE(FirstName + ' ' + MiddleName + ' ' + LastName + ' ' + Suffix, ' ', ' ') AS FullName
HTH