SQL Server 2005:charindex starting from the end

后端 未结 6 1879
情深已故
情深已故 2020-12-31 08:09

I have a string \'some.file.name\',I want to grab \'some.file\'.

To do that,I need to find the last occurrence of \'.\' in a string.

My solution is :

6条回答
  •  北海茫月
    2020-12-31 08:53

    Here is a shorter version

    DECLARE @someStr varchar(20)
    set @someStr = '001.002.003'
    
    SELECT REVERSE(Substring(REVERSE(@someStr),CHARINDEX('.', REVERSE(@someStr))+1,20))
    

提交回复
热议问题