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.
| Author |
Topic |
|
jparker
Posting Yak Master
118 Posts |
Posted - 2006-08-11 : 05:23:51
|
| HelloI am working on trying to return the initial or forename in a name stringFor example, I have a nameMr J Parkerand I want to return the J or James in the stringI have done the first part of removing the title from the stringselect top 1 SUBSTRING(name, charindex(' ', name)+1, len(name))from tblnamesreturnsJ Parkerbut I need to take it a stage further so it returns Jor JamesCan you help please |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-08-11 : 05:31:51
|
| If v2005 then seehttp://www.simple-talk.com/sql/sql-server-2005/sql-server-2005-common-table-expressions/The bit about splitting csv stringsotherwise 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. |
 |
|
|
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 latterWould 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 spacethanks |
 |
|
|
jparker
Posting Yak Master
118 Posts |
Posted - 2006-08-11 : 05:46:11
|
| I've worked it out something like this will do itleft(SUBSTRING(name, charindex(' ', name)+1, len(name)), charindex(' ', SUBSTRING(name, charindex(' ', name)+1, len(name)))-1)thanks for looking at this post though :) |
 |
|
|
|
|
|
|
|