-4

Possible Duplicate:
How can I parse the first, middle and last name from a full name field in SQL?

Say I have some nvarchar data 'Joe Blogs'...

I need to be able to query the data to extract the first and last names.

firstname
----------
Joe

lastname
----------
Blogs

What is the simplest way of doing this?

Community
  • 1
  • 1
user971543
  • 53
  • 1
  • 5
  • Are you talking about a simple word splitting mechanism, or a function to semantically determine which part is the first name and which the last? What happens with the input string `Ponce de Leon`? Also, the title has nothing to do with the question's content... – Esoteric Screen Name Dec 03 '12 at 16:04
  • 1
    Also have you [searched the archives](http://stackoverflow.com/search?q=[sql]+extract+first+last+name)? As this is a very common question. Possibly one of the previous responses may answer your question - or if not - help you refine this one. – Leigh Dec 03 '12 at 17:10

1 Answers1

1

You need to create a T-SQL function that splits a string, based on a delimiter, and returns the tokens (pieces). There are a number available, such as this one:

T-SQL split string

Community
  • 1
  • 1
Randy Minder
  • 47,200
  • 49
  • 204
  • 358