Keith Walton Keith Walton - 1 year ago 69
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download