SQL Server 2005:charindex starting from the end

后端 未结 6 1883
情深已故
情深已故 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:37

    This will also work:

    DECLARE
         @test     VARCHAR(100)
    
    SET @test = 'some.file.name'
    
    SELECT
         LEFT(@test, LEN(@test) - CHARINDEX('.', REVERSE(@test)))
    

提交回复
热议问题