SQL server split column

In SQL Server:

I've got a FullName column formatted like:
Smith, Tom

I want to split out the values to separate columns:

FirstName
LastName
webdorkAsked:
Who is Participating?
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
UPDATE urTable SET
FirstName =  SUBSTRING(FullName,1,CHARINDEX(',',FullName)-1),
LastName =  LTRIM(SUBSTRING(FullName,CHARINDEX(',',FullName)+1,LEN(FullName)))
0
 
webdorkAuthor Commented:
Ok it works... One thing though it places the first name in the LastName column and vis versa. Can you redo with SQL?
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
just interchange the column names''UPDATE urTable SET
LastName=  SUBSTRING(FullName,1,CHARINDEX(',',FullName)-1),
FirstName =  LTRIM(SUBSTRING(FullName,CHARINDEX(',',FullName)+1,LEN(FullName)))
0
 
webdorkAuthor Commented:
Thank You
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.