sql2005形如: select * from id = '"+ strID +"';表中id可能为null, 
strID有两种情况,为0或者为1:
为0的时候,字段id为null的也要检索出来
为1的时候就是id为1的时候这条语句该怎么写?我上面写的检索不到id为null的时候

解决方案 »

  1.   

    1.select ISNULL(id,0) id,其它字段 from table where id = '"+ strID +"';2.可以使用case when,原理一样是讲NULL列转为指定值
      

  2.   


    第一种方式就是这样写了?
    select * from table where isnull(id, 0) = '"+ strID +"';
    这样就把strID为0和1的两种状态都检索到了是吧?
    我试验一下
      

  3.   

    如果是oracle数据库,就用NVL函数。
      

  4.   

    select * from table where isnull(id, 0) = '"+ strID +"';
    这句正确
      

  5.   

    sql="select * from table where isnull(id, 0) = "+ strID ;
      

  6.   

    sql="select * from table where isnull(id, 0) = "+ strID ;
    或者
    case when 查询
      

  7.   

    select * from table where id=strID == 0 ? 0: 1
      

  8.   


    性能原则:where子句左式尽量避免逻辑运算,需要和谐掉这种情况,海量数据会产生性能瓶颈