February 1, 2016 at 1:49 am
If I have a string like W:\ABC\F1.bak, is there any way to capture just W:\ABC, it is not necessary that it could be just W:\ABC, it could be W:\ABCD as well, the main intention is that if there are 2 backslashes in the entire string, I would like to capture the entire text before the second backslash or in other words i want to caapture the entire string except .bak, .trn and so on.
Any help would be Highly Appreciated.
February 1, 2016 at 1:57 am
This will return the string before the last backslash. It'll work if there's more than 2.
DECLARE @STR VARCHAR(200) = 'W:\ABC\F1.bak'
SELECT LEFT(@Str, LEN(@Str) - CHARINDEX('\', REVERSE(@Str)))
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply