Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Split out FirstName, LastName, MiddleName Expand / Collapse
Author
Message
Posted Thursday, December 5, 2013 12:36 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, November 14, 2014 1:46 PM
Points: 322, Visits: 623
One column name as [MemberName] in which stored data like

LastName, FirstName M (with initial middle name)

or

LastName, FirstName (without initial middle name)

How to create a function to split out two columns [First name] and [Last name]?
Post #1520298
Posted Thursday, December 5, 2013 12:44 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 7:30 PM
Points: 3,943, Visits: 8,950
Something like this?

WITH CTE([MemberName])AS(
SELECT 'Cazares, Luis' UNION ALL
SELECT 'Cazares, Luis A')
SELECT LEFT( MemberName, CHARINDEX(',', MemberName) - 1) LastName,
SUBSTRING( MemberName, CHARINDEX(',', MemberName) + 1, LEN( MemberName)) FirstName
FROM CTE




Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1520305
Posted Thursday, December 5, 2013 12:53 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, November 14, 2014 1:46 PM
Points: 322, Visits: 623
Thank you for help.
We are getting there but if MemberName is 'Cazares, Luis A' I want to display as 'Cazares, Luis' as well.
How modify code?
Post #1520309
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse