zoukankan      html  css  js  c++  java
  • SqlServer-- NULL空值处理

     数据库中,一个列如果没有指定值,那么值就为null,数据库中的null表示“不知道”,而不是表示没有。因此select null+1结果是null,因为“不知道”加1的结果还是“不知道”。
    select * from score where english = null ;
    select * from score where english != null ;都没有任何返回结果,因为数据库也“不知道”。
    SQL中使用is null、is not null来进行空值判断:

    select * from score where english is null ; select * from score where english is not null ;
    ISNULL ( check_expression , replacement_value )

    select * from TblStudent

    --查询所有年龄是null的同学信息

    --null值无法使用=或<>来进行比较

    --unknown

    --判断null值必须使用is null或者is not null

    select * from TblStudent where tsage is null

    select * from TblStudent where tsage=null

    --查询所有年龄不是null的同学

    select * from TblStudent where tsage<>null

    select * from TblStudent where tsage is not null

    select * from TblStudent where tsage=25

    select * from TblStudent where tsage<>25

    --任何值与null进行计算,得到的结果还是null

    select 2000+null

  • 相关阅读:
    [学习笔记]多维偏序
    SCOI2009 游戏
    置换群和Burnside引理,Polya定理
    AC自动机——多个kmp匹配
    51nod 1667 概率好题
    分块——优化的暴力
    [Cqoi2014]数三角形——组合数
    C++ 中的导致编译错误汇总
    哈夫曼树Huffman
    导出查询结果到csv文件
  • 原文地址:https://www.cnblogs.com/hao-1234-1234/p/6185243.html
Copyright © 2011-2022 走看看