zoukankan      html  css  js  c++  java
  • 数据库null值小议

    在数据库的查询过程中,遇到以下问题:
    当select * from tKeyword where typeId = case when @typeId < 0 then null else @typeId end order by orderNo desc
    这句话是正确的,但是当@typeId < 0不出结果,而数据库中有满足条件typeId=null的数据。
    后来进行了以下处理:
    if @typeId < 0 then
        select * from tKeyword where typeId is null order by orderNo desc
    else
        select * from tKeyword where typeId = @typeId order by orderNo desc
    问题得到解决了。进一步简化问题如下:
    select * from tKeyword where isnull(typeId,@typeId)=@typeId end order by orderNo desc
    显示这是一种更为简化的处理方法。

    在数据操作时,一定要注意字段的null的处理方法。
    好了,以后有机会在写了。

  • 相关阅读:
    贝叶斯定理经典案例
    java 简单秒杀
    menu JPopupMenu JTabbedPane
    java String matches 正则表达
    gg mirror
    后台计时
    css 标题
    ajax dataType
    jQuery ajax
    java null 空指针
  • 原文地址:https://www.cnblogs.com/zsy/p/443018.html
Copyright © 2011-2022 走看看