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: Thursday, July 24, 2014 7:27 AM
Points: 306, Visits: 580
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:11 AM
Points: 3,342, Visits: 7,228
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.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

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: Thursday, July 24, 2014 7:27 AM
Points: 306, Visits: 580
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