Combine First, Middle Initial, Last name and Suffix in T-SQL (No extra spaces)

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2010-04-23T15:30:29Z Indexed on 2010/04/23 15:33 UTC
Read the original article Hit count: 141

Filed under:

I'm trying not to reinvent the wheel here...I have these four fields

[tbl_Contacts].[FirstName], [tbl_Contacts].[MiddleInitial], [tbl_Contacts].[LastName], [tbl_Contacts].[Suffix]

And I want to create a FullName field in a view, but I can't have extra spaces if fields are blank...So I can't do FirstName + ' ' + MiddleInitial + ' ' + LastName + ' ' + Suffix...Because if there is no middle initial or suffix I'd have 2 extra spaces in the field. I think I need a Case statement, but I thought someone would have a handy method for this...Also, the middleinitial and suffix may be null.

© Stack Overflow or respective owner

Related posts about tsql