这回的字符串里有很多/,数量不固定,  
要最后那个/后面的那段字符  
 
我现在的办法是一遍一遍执行:  
update  tab1  set  col1  =  right(col1,len(col1)-charindex('/',col1))    
 
能不能一下就搞定??

解决方案 »

  1.   

    select reverse(left(REVERSE(col1) , charindex('/',REVERSE(col1) - 1))) from tb
      

  2.   

    update  tab1  set  col1  = REVERSE(left(REVERSE(col1),charindex('/',REVERSE(col1)-1)))
      

  3.   

    update  tab1  set  col1  =  REVERSE(left(REVERSE (col1),charindex('/',REVERSE (col1)) ) )
      

  4.   

    不用那麼麻煩Declare @S Varchar(1000)
    Select @S = 'as/de/fgrt/dada/kk'
    Select Right(@S, CharIndex('/', REVERSE(@S)) - 1)
    --kk
      

  5.   

    用在你的表上的就是Select Right(字段, CharIndex('/', REVERSE(字段)) - 1) As 字段  From 表
      

  6.   

    declare @s as varchar(20)
    set @s = '12345/67890/abcde'select reverse(left(reverse(@s),charindex('/',reverse(@s)) - 1)) result
    result               
    -------------------- 
    abcde(所影响的行数为 1 行)
      

  7.   

    update tab1 set col1=reverse(left(reverse(col1),charindex('/',reverse(col1))-1))
      

  8.   

    --創建測試環境
    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
    */
      

  9.   

    update tab1
    set  col1= Right(col1, CharIndex('/', REVERSE(col1)) - 1)