String Concatenation with Nulls and Spaces

  • Hehe something that seemed so simple turned out to be a real monster. It's a nice touch to see that I didn't account for empty non null names. Still so much to learn .

  • Try looking at the COALESCE funtion, it's been around for a while (I think since v4.21) since your in v6.5 compatibility mode.

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • Since I do this on a semi-regular basis, I am going to go ahead and create a function similar to Aaron's suggestion.

    I sincerely thank all of you who responded to my initial post.  I have learned something from all of your responses.


    Todd Capehart

  • Depending upon how often you use this, and whether you do a SELECT * from the table very often without needing this merged value, you may want to consider creating a computed column. Using my previous function, you would add a FullName column to the table definition and in the "Formula" part put the following code. Note that it will clear out the data type when you put in the formula since it is subject to the code within the formula.

    dbo.BuildFullName( dbo.BuildFullName( dbo.BuildFullName( dbo.BuildFullName( dbo.BuildFullName( '', Salutation), FirstName ), MiddleName ), LastName ), NameSuffix )

     

Viewing 4 posts - 16 through 18 (of 18 total)

You must be logged in to reply to this topic. Login to reply