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 05, 2013 12:36 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 12:04 PM
Points: 291, Visits: 559
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 05, 2013 12:44 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 2:13 PM
Points: 2,784, Visits: 5,965
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 05, 2013 12:53 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 12:04 PM
Points: 291, Visits: 559
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