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 2008 Forums
 Transact-SQL (2008)
 Want to return character(s) after a dash (-)

Author  Topic 

Darts75
Starting Member

27 Posts

Posted - 2015-03-24 : 00:14:32
Hi Everyone,

I want to return the character(s) in a string directly after a dash (-) character. For example in the following numbers 72187-1 & 72187-2 I am interested in returning 1 & 2 respectively.

It is possible in my scenario that the number after the dash is two digits long, e.g.: 72187-12 in which case I want to return 12.

Any help here will be greatly appreciated.

Kind Regards,

David

sz1
Aged Yak Warrior

555 Posts

Posted - 2015-03-24 : 05:31:12
Try:

Will return all chars after the -

SELECT REVERSE(LEFT(REVERSE('72187-2'),CHARINDEX('-',REVERSE('72187-2'))-1))


We are the creators of our own reality!
Go to Top of Page
   

- Advertisement -