467,917 Members | 1,385 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,917 developers. It's quick & easy.

Find last index of character in string

jkmyoung
Expert 2GB
Hi, can anyone point me to a function in MSSQL that returns the last index of a character in a string? I'm trying to find the base filename from a field that returns the full path.

Eg. if db contained rows:
C:\temp\file1.bat
C:\temp\Aug10\file2.bat

I would want as result:
file1.bat
file2.bat


The only solution I've come up with so far is to create a temporary table with the filenames, and recurse using update statements on the table until there are no more updates. There has to be a better solution.
Oct 8 '08 #1
  • viewed: 31025
Share:
1 Reply
ck9663
Expert 2GB
Use CHARINDEX() to find the last "\". Start the search from the right.

Then use RIGHT() or SUBSTRING(). You might also need the LEN() function.

Good luck

-- CK
Oct 8 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

108 posts views Thread by Bryan Olson | last post: by
19 posts views Thread by ashmangat | last post: by
14 posts views Thread by micklee74 | last post: by
6 posts views Thread by Oliver Bleckmann | last post: by
4 posts views Thread by Dameon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.