Get everything after and before certain character in SQL Server

前端 未结 15 1909
臣服心动
臣服心动 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:25

    Inspired by the work of Josien, I wondered about a simplification.

    Would this also work? Much shorter:

    SELECT SUBSTRING(col, CHARINDEX ('/', col) + 1, CHARINDEX ('.', col) - CHARINDEX ('/', col) - 1);
    

    (I can't test right now because of right issues at my company SQL server, which is a problem in its own right)

提交回复
热议问题