2016.7.10 SqlServer语句中类似decode、substr、instr、replace、length等函数的用法

Decode() 对应 case when函数

case CHARINDEX('/',start_point_name)

when 0 then start_point_name

else substring(start_point_name,1,CHARINDEX('/',start_point_name)-1)

end

注意:sqlserver在用case when判断是否为null时,语法不一样

判断null应该用:

case when identifier is null then airway_point_name else identifier  end,

最简单的办法就是用isnll函数 isnull(idenfier, airway_point_name)

不行!isnull(idenfier, airway_point_name)会将idenfier缩短,本来5个字符,替换后只有4个字符,原因未知,最好不用isnull

 

instr对应CHARINDEX('/',start_point_name)函数,只不过两个参数的含义正好颠倒,也是从1开始计数

 

substr对应substring 参数完全一样,但长度参数不能缺少,不能默认到末尾,只能给一个足够大的长度值。

 

replace函数则完全一样

 

length函数对应 len函数

posted on 2016-10-15 18:13  mol1995  阅读(2162)  评论(0编辑  收藏  举报

导航