Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

823 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