先移转,再查询

SELECT case when charindex('12',s) =0 then 0 else length(s)-charindex(reverse('12'),reverse(s)) end AS lastIndexOf, s FROM t; 

 

利用存储过程,一个个找:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[lastindexof] (@stringValue as nvarchar(1000), @stringSearch as nvarchar(1000), @startPosition as int = 0)
returns int
AS
BEGIN
     DECLARE @lastindex int
     SET @lastindex= 0
     DECLARE @tempindex int
     while (1=1)
     begin
        SET @tempindex = charindex(@stringSearch, @stringValue, @lastindex + 1)
        if (@tempindex = 0)
            break
        SET @lastindex = @tempindex
     end
    
     RETURN(@lastindex)
END






 

 

相关文章:

  • 2021-11-17
  • 2022-01-06
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2022-03-09
  • 2021-07-04
相关资源
相似解决方案