By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,574 Members | 1,977 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,574 IT Pros & Developers. It's quick & easy.

Find last index of character in string

Expert 100+
P: 2,057
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:

I would want as result:

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
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 2,878
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.