日期:2014-05-19  浏览次数:20437 次

下班前最后一问:还是字符串分割要后面那段

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

------解决方案--------------------
select reverse(left(REVERSE(col1) , charindex( '/ ',REVERSE(col1) - 1))) from tb
------解决方案--------------------
update tab1 set col1 = REVERSE(left(REVERSE(col1),charindex( '/ ',REVERSE(col1)-1)))


------解决方案--------------------
update tab1 set col1 = REVERSE(left(REVERSE (col1),charindex( '/ ',REVERSE (col1)) ) )
------解决方案--------------------
用在你的表上的就是

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))
------解决方案--------------------
鱼的最简洁效率高
------解决方案--------------------
update tab1
set col1= Right(col1, CharIndex( '/ ', REVERSE(col1)) - 1)