首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-03-26 
下班前最后一问:还是字符串分割要后面那段 这回的字符串里有很多/,数量不固定,要最后那个/后面的那段字符

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

这回的字符串里有很多/,数量不固定,    
要最后那个/后面的那段字符    
 
我现在的办法是一遍一遍执行:    
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)

热点排行