当前位置: 代码迷 >> Sql Server >> special =left(b.dynaev1,len(b.dynaev1)-charindex('X'reverse(b.dynaev1)))解决方法
  详细解决方案

special =left(b.dynaev1,len(b.dynaev1)-charindex('X'reverse(b.dynaev1)))解决方法

热度:436   发布时间:2016-04-24 11:04:35.0
special =left(b.dynaev1,len(b.dynaev1)-charindex('X',reverse(b.dynaev1)))
求大大们解释一下这段
special  =left(b.dynaev1,len(b.dynaev1)-charindex('X',reverse(b.dynaev1)))

是什么意思...
越详细越好,我看不懂= =!
------解决方案--------------------
引用:
Quote: 引用:

reverse是反转函数。将dynaev1反转

CHARINDEX判断反转以后的第一个X的位置

LEN是长度

LEFT截取。



baseunitrate =  convert( int ,right(b.dynaev1,len ( b.dynaev1)- len(left(b.dynaev1,len(b.dynaev1)
-charindex('X',reverse(b.dynaev1)))  )-1))

那这句呢?


给你一个例子;
select baseunitrate =  convert( int ,right(b.dynaev1,len ( b.dynaev1)- len(left(b.dynaev1,len(b.dynaev1)
-charindex('X',reverse(b.dynaev1)))  )-1))
from
(
select '100X100X5'  dynaev1
)b
/*
baseunitrate
5
*/

------解决方案--------------------

select baseunitrate =  convert( int ,right(b.dynaev1,len ( b.dynaev1)- len(left(b.dynaev1,len(b.dynaev1)
-charindex('X',reverse(b.dynaev1)))  )-1))
from
(
select '100X100X5'  dynaev1
)b
/*
baseunitrate
5
*/

这个代码的意思应该是,找字符串中的最后一个x,之后的数字,提取出来
------解决方案--------------------
你拿个字符串,替换b.dynaev1这个列名,然后逐部分执行一下,体会一下,然后看看联机丛书
  相关解决方案