declare @T table
(
Col varchar(20)
)
insert into @T
Select 'images/test1.jpg'
union all
Select 'images/test2.png'
union all
Select 'images/test3.jpg'
union all
Select 'images/test4.jpeg'
union all
Select 'images/test5.jpeg'
Select substring( LEFT(Col,charindex('.',Col)-1),charindex('/',Col)+1,len(LEFT(Col,charindex('.',Col)-1))-1 )
from @T
declare @test varchar(25) = 'images/test.jpg'
select
@test as column_name
, parsename(replace(@test,'/','.'),1) as jpg
,parsename(replace(@test,'/','.'),2) as test
,parsename(replace(@test,'/','.'),3) as images
DECLARE @rightidx int = CASE
WHEN 'images/images/test.jpg' IS NULL OR (CHARINDEX('.', 'images/images/test.jpg')) <= 0 THEN LEN('images/images/test.jpg')
ELSE (CHARINDEX('.', REVERSE('images/images/test.jpg')) - 1)
END
SELECT RIGHT('images/images/test.jpg', @rightidx)