用在你的表上的就是Select Right(字段, CharIndex('/', REVERSE(字段)) - 1) As 字段 From 表
declare @s as varchar(20) set @s = '12345/67890/abcde'select reverse(left(reverse(@s),charindex('/',reverse(@s)) - 1)) result result -------------------- abcde(所影响的行数为 1 行)
update tab1 set col1=reverse(left(reverse(col1),charindex('/',reverse(col1))-1))
--創建測試環境 Create Table TEST(Name Varchar(1000)) Insert TEST Select 'as/de/fgrt/dada/kk' Union All Select 'as/de/fgrt/ddasdada' Union All Select 'grt/dada/12321fsdaas' GO --測試 Select Right(Name, CharIndex('/', REVERSE(Name)) - 1) As Name From TEST GO --刪除測試環境 Drop Table TEST --結果 /* Name kk ddasdada 12321fsdaas */
update tab1 set col1= Right(col1, CharIndex('/', REVERSE(col1)) - 1)
Select @S = 'as/de/fgrt/dada/kk'
Select Right(@S, CharIndex('/', REVERSE(@S)) - 1)
--kk
set @s = '12345/67890/abcde'select reverse(left(reverse(@s),charindex('/',reverse(@s)) - 1)) result
result
--------------------
abcde(所影响的行数为 1 行)
Create Table TEST(Name Varchar(1000))
Insert TEST Select 'as/de/fgrt/dada/kk'
Union All Select 'as/de/fgrt/ddasdada'
Union All Select 'grt/dada/12321fsdaas'
GO
--測試
Select Right(Name, CharIndex('/', REVERSE(Name)) - 1) As Name From TEST
GO
--刪除測試環境
Drop Table TEST
--結果
/*
Name
kk
ddasdada
12321fsdaas
*/
set col1= Right(col1, CharIndex('/', REVERSE(col1)) - 1)