Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

Concatenating name columns

I’m using sql server.

I have a table that has a lastname,firstname and middleinitial columns.
They are these datatypes:

[LastName] VARCHAR(30)
[FirstName] VARCHAR(20)
[MidInit] VARCHAR(1)

So when I run this query

SELECT [LastName],[FirstName],[MidInit]
FROM [Emplyoees]

I get this:

LastName FirstName MidInit
Simpson    Homer       J
Simpson    Lisa            M
Bunny        Bugs
Bonney      William      H

I would like to create a column called FullName that displays the data in this format LastName, FirstName MidInit

So then the new column would like like this:

FullName
Simpson, Homer J
Simpson, Lisa M
Bunny, Bugs
Bonney, William H

What’s the beat syntax to create this column?

Notice how bugs bunny has no MidInit.
When employee has no MidInit don’t place any character in the string for the middleinit.
ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maqskywalker
maqskywalker

ASKER

thanks.