• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 951
  • Last Modified:

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
0
webdork
Asked:
webdork
  • 2
  • 2
1 Solution
 
Aneesh RetnakaranDatabase 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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now