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
Solved

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

Posted on 2009-06-30
3
411 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
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

807 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