Solved

How to extract last and first name from a full name field

Posted on 2009-06-30
3
428 Views
Last Modified: 2012-05-07
I have a field calle fullname with the convention of  "Lastname, Firstname" in the varchar field.  Example   Jones, Bill.

How can I extract just the lastname and then just the firstname?

I want to end up with Bill Jones and I assume I must seperate them first, then concatonate to put them together in desired order.

Help please
0
Comment
Question by:SteveRed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 24749965
SELECT LEFT (Name, CHARINDEX(',', Name)-1) FirstName, LTRIM( RIGHT (name, LEN(Name) - CHARINDEX(',', Name)) ) LasrtName
FROM urTabl
WHERE CHARINDEX(',', Name) > 0
0
 
LVL 3

Expert Comment

by:PurpleHaze
ID: 24751852
Another Way

Declare @FullName Varchar(100)
Set @FullName = 'Jones, Bill'
Select Substring(@FullName, CharIndex(',', @FullName, 0) + 2, DataLength(@FullName)) + ' ' + Substring(@FullName, 0, CharIndex(',', @FullName, 0)) As MyOrder
0
 

Author Closing Comment

by:SteveRed
ID: 31598554
thank you!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question