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
 General SQL Server Forums
 New to SQL Server Programming
 Starting from right, not left

Author  Topic 

dmilam
Posting Yak Master

185 Posts

Posted - 2010-09-01 : 14:29:15
By this I mean, how to count or determine the position of a character starting from the right, not from the left. It seems that charindex and patindex start from the left, or am I just misunderstanding them?

I have strings that end with A, B, C in the third position from the right, but the string lengths vary.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-09-01 : 14:45:19
You can use the REVERSE function and then the *INDEX functions.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dmilam
Posting Yak Master

185 Posts

Posted - 2010-09-01 : 15:05:50
Reverse! Thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-09-01 : 15:07:35
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-09-01 : 15:14:52
If your goal is to find all records that has either A, B or c as the third character from the right, you can also use LIKE operator.

SELECT * FROM Table1 WHERE Col1 LIKE '%[ABC]__'



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -