Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need to Parse First and Last Name

Author  Topic 

bconner
Starting Member

48 Posts

Posted - 2009-12-09 : 15:04:31
I have a field called [Patient_Name] and it holds a name in the following format KOOP,SHIRLEY A (Last,First Middle). I am able to extract the last name but cannot figure out how to grab the First Name without middle initial. In the example name KOOP,SHIRLEY A I only want to grab SHIRLEY


Brian

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-09 : 15:13:47
So does Tiger


DECLARE @x varchar(256)
SET @x = 'KOOP,SHIRLEY A'
SELECT '"' +
SUBSTRING(@x,CHARINDEX(',',@x)+1
,CHARINDEX(' ',@x)-CHARINDEX(',',@x)-1)
+ '"'




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-12-09 : 15:27:08
Speaking of Tiger...

Name parsing is tricky when you have name variations. ie:

Tiger
Woods, Tiger
Von Schtup, Gretta Marie Z

And if you have prefixes and suffixes thrown in there it gets really hard.
check this out:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56499&SearchTerms=parse,names

Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-10 : 01:45:46
This will give you some more ideas
http://sqlblogcasts.com/blogs/madhivanan/archive/2009/11/18/parsing-a-string.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -