zoukankan      html  css  js  c++  java
  • 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函数

  • 相关阅读:
    单分发器
    Python 虚拟环境
    $modal
    memoization
    directive例子2
    UI-Router
    angular-translate
    directive例子1
    FileInputStream/FileOutputStream的应用
    自定义readLine
  • 原文地址:https://www.cnblogs.com/mol1995/p/5965010.html
Copyright © 2011-2022 走看看