Solved

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

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Where clause in stored procedure 8 64
how many extra RAM for SQL server is needed 23 48
passing parameter in sql procedure 9 68
Help  needed 3 45
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.

696 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