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
 Transact-SQL (2000)
 Substring

Author  Topic 

ckuo@kahluadesigns.com
Yak Posting Veteran

58 Posts

Posted - 2004-02-19 : 16:20:18
Hi,
Say I have this string '100-101-102'
How can I use sql to get the left part of the string up to the last '-', so i get '100-101'. I have have any number of '-', but I jus need to chop off everything after the last one. Thanks. I have tried using CharIndex, but i dont know how to start from the right side.

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-02-19 : 16:35:21
[code]SELECT REVERSE(SUBSTRING(REVERSE('100-101-102'),CHARINDEX('-',REVERSE('100-101-102'),1)+1,LEN('100-101-102')))[/code]
Go to Top of Page

ckuo@kahluadesigns.com
Yak Posting Veteran

58 Posts

Posted - 2004-02-19 : 16:53:31
THANKS! That select is a good tutorial in of itself.
Go to Top of Page
   

- Advertisement -