1

I have table Customers:

Name
David Smith
John David
Jonathan Greg

and i want to transfer it to table Customers2 :

Name      Surname
David     Smith
John      David
Jonathan  Greg

How can i split those names into Name/Surname?

Thank you

Nightmaresux
  • 538
  • 3
  • 12

2 Answers2

2

Perhaps this but a space better be the deliminator...

Create table customers2 (
SELECT PARSENAME(REPLACE(Name, ' ', '.'), 2) AS [FirstName],
       PARSENAME(REPLACE(Name, ' ', '.'), 1) AS [LastName]
FROM Customers)
xQbert
  • 34,733
  • 2
  • 41
  • 62
1

Assuming it is strictly name + surname, you can do this

SELECT PARSENAME(REPLACE('David Smith', ' ', '.'), 1) AS NAME,
       PARSENAME(REPLACE('David Smith', ' ', '.'), 1) AS SURNAME
C.J.
  • 3,409
  • 8
  • 34
  • 51