Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove everything to the right of the LAST nth character

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hello, I have the following in a varchar field:

c:\temp\123.tif
c:\temp\124.tif
c:\temp\images\124.tif
c:\temp\images\today\125.tif

I would like to remove everything to the right of the last '\' so I end up with
c:\temp
c:\temp
c:\temp\images
c:\temp\images\today

I have been trying charindex, but it's not working out for me:

Code:
select left(myfield, CHARINDEX( '\', reverse(myfield)))from mytable

Can someone help me out with this?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top