T-SQL query problem

advertisements

I have a column in Database called Full Name and I want split that name as FirstName and LastName:

Here is an Example:

FullName Sam Peter

I want this to be

FirstName   LastName
--------------------
Sam          Peter

But the Problem is Some of the columns in Database have Full Names Like this

FullName
--------
Sam George Jack Peter
Sam Adam Peter

I want this to be

FirstName           LastName
---------           --------
Sam George Jack     Peter
Sam Adam            Peter

How do I write T-SQL Query for this.

Thanks in Advance for all the help


There's a very thorough name parsing routine described in this answer. It handles your situation, along with much trickier cases like "Mr. Martin J Van Buren III".