Keith Walton Keith Walton - 13 days ago 4x
SQL Question

What's the shortest TSQL to concatenate a person's name which may contain nulls

3 fields: FirstName, MiddleName, LastName

Any field can be null, but I don't want extra spaces. Format should be "First Middle Last", "First Last", "Last", etc.


use a UDF:

`Select udfConcatName(First, Middle, Last) from foo`

That way all your logic for concatenating names is in one place and once you've gotten it written it's short to call.