Get everything after and before certain character in SQL Server

前端 未结 15 1908
臣服心动
臣服心动 2020-12-07 18:48

I got the following entry in my database:

images/test.jpg

I want to trim the entry so I get: test

So basically, I want

15条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 19:28

     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
    

提交回复
热议问题