Full Name – get rid of the empty space if middle name is null
Posted on Sunday, March 6, 2016
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.
FullName = (reader["FirstName"].ToString() + " " + reader["MiddleName"].ToString() + " " + reader["LastName"].ToString()).Replace(" ", " ");
REPLACE(FirstName + ' ' + MiddleName + ' ' + LastName + ' ' + Suffix, ' ', ' ') AS FullName