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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 name split

Author  Topic 

jparker
Posting Yak Master

118 Posts

Posted - 2006-08-11 : 05:23:51
Hello

I am working on trying to return the initial or forename in a name string

For example, I have a name

Mr J Parker

and I want to return the J or James in the string

I have done the first part of removing the title from the string

select top 1 SUBSTRING(name, charindex(' ', name)+1, len(name))
from tblnames

returns

J Parker

but I need to take it a stage further so it returns

J

or

James

Can you help please


nr
SQLTeam MVY

12543 Posts

Posted - 2006-08-11 : 05:31:51
If v2005 then see
http://www.simple-talk.com/sql/sql-server-2005/sql-server-2005-common-table-expressions/
The bit about splitting csv strings
otherwise charindex has a third parameter as the start position - use the charindex statement you have for tha6t and you will get the second value in the string.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jparker
Posting Yak Master

118 Posts

Posted - 2006-08-11 : 05:37:37
I'm using SQL Server 2000 so unfortunately that rules out the first option and I'm not sure I understand what you are saying regarding the latter

Would you mind putting a quick example together as I don't see how that works for getting the value between the first and the second space

thanks
Go to Top of Page

jparker
Posting Yak Master

118 Posts

Posted - 2006-08-11 : 05:46:11
I've worked it out something like this will do it

left(SUBSTRING(name, charindex(' ', name)+1, len(name)), charindex(' ', SUBSTRING(name, charindex(' ', name)+1, len(name)))-1)

thanks for looking at this post though :)
Go to Top of Page
   

- Advertisement -