Reputation: 149
I tried lots of things but could not find any accurate answer, My question is how to find last string of a file path without extension.
For example my path is :
~/Document/UK_0004/OldStateNoc/THE_RAIN.txt
and I want result like this
Output: THE_RAIN
I tries this, But not get sufficient answer
DECLARE @st1 VARCHAR(max)
SET @st1 = '~/Document/UK_0004/OldStateNoc/THE_RAIN.txt'
select right(@st1, charindex('/', reverse(@st1)) - 1)
this give me
THE_RAIN.txt
I also dont want extension of file also, Please anyone help me on this.
Upvotes: 0
Views: 336
Reputation: 3473
use your same method for '.' also. ANd it will work
DECLARE @st1 VARCHAR(max)
SET @st1 = '~/Document/UK_0004/OldStateNoc/THE_RAIN.txt'
Declare @st2 varchar(max)
(select @st1 = right(@st1, charindex('/', reverse(@st1)) - 1))
select left(@st1, charindex('.', @st1)-1)
Upvotes: 2