Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
CHARINDEX in reverse
16 posts, Page 2 of 2
««
1
2
CHARINDEX in reverse
Rate Topic
Display Mode
Topic Options
Author
Message
Sergiy
Sergiy
Posted Sunday, July 05, 2009 9:29 PM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 5:01 PM
Points: 4,540,
Visits: 8,184
Jeff Moden (7/2/2009)
Andrew already did exactly what I would do...
I would not.
There was a member of Led Zeppelin, John Paul Jones.
Would not be happy seeing his name after such "parsing".
Post #747484
nigel.
nigel.
Posted Monday, July 06, 2009 8:35 AM
Ten Centuries
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 3:57 AM
Points: 1,163,
Visits: 2,600
Sorry, did the same as Jeff, didn't read Andrews answer and posted the same solution.
--
Nigel
Useful Links:
How to post data/code on a forum to get the best help
The "Numbers" or "Tally" Table - Jeff Moden
Post #747785
nigel.
nigel.
Posted Monday, July 06, 2009 8:38 AM
Ten Centuries
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 3:57 AM
Points: 1,163,
Visits: 2,600
...twice !! dozy ******
--
Nigel
Useful Links:
How to post data/code on a forum to get the best help
The "Numbers" or "Tally" Table - Jeff Moden
Post #747788
Terri-92562
Terri-92562
Posted Monday, July 06, 2009 10:12 AM
SSC Veteran
Group: General Forum Members
Last Login: Wednesday, October 03, 2012 8:35 AM
Points: 242,
Visits: 1,242
andrewd.smith (7/1/2009)
REVERSE is one of the less performant string functions in TSQL, so this alternative expression calls REVERSE only once.
SELECT RIGHT(@nam, CHARINDEX(' ', REVERSE(@nam)) - 1)
Bear in mind that this only returns the last name if the last name contains no spaces. My last name consists of 2 words separated by a space and it is parsing routines such as this that send me mail to the last half of my name or file me under the wrong letter. Of course the real problem is the that the name is not stored in separate fields to begin with.
Terri
To speak algebraically, Mr. M. is execrable, but Mr. C. is
(x+1)-ecrable.
Edgar Allan Poe
[Discussing fellow writers Cornelius Mathews and William Ellery Channing.]
Post #747870
andrewd.smith
andrewd.smith
Posted Monday, July 06, 2009 12:10 PM
Ten Centuries
Group: General Forum Members
Last Login: Wednesday, October 24, 2012 2:12 PM
Points: 1,213,
Visits: 3,232
Of course the real problem is the that the name is not stored in separate fields to begin with.
Agreed.
Post #747932
Jeff Moden
Jeff Moden
Posted Monday, July 06, 2009 2:54 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 9:57 PM
Points: 32,893,
Visits: 26,771
Sergiy (7/5/2009)
Jeff Moden (7/2/2009)
Andrew already did exactly what I would do...
I would not.
There was a member of Led Zeppelin, John Paul Jones.
Would not be happy seeing his name after such "parsing".
Sergiy is actually the most correct on this. Full name parsing is dangerous at best especially considering that you can have 3 part last names like Van de Graff or the like. The proper way to do this is to head the data provider in the head with a bat and get them to provide the data in the correct format of last name being it's own column.
I've built a splitter for this type of thing including many of the 3 part names, but no lookup list in the world is going to be able to resolve all the names in the world. The data must be entered correctly in some GUI somewhere.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #748073
« Prev Topic
|
Next Topic »
16 posts, Page 2 of 2
««
1
2
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.