A表中有字段b
if 参数c不等于NULL时 取出下列集合
select b from a where b = 参数c
if 参数c等于NULL时 取出下列集合
select b from a where b IS NOT NULL
如何把这两个写成一个SQL呀?

解决方案 »

  1.   

    select * from a where (b is not null and 参数c is null) or(参数c is not null and b=参数c)
      

  2.   

    select b from a where b = isnull(参数c,b)
      

  3.   

    select b from a where nvl(b,'一个在b中不可能出现的值') = nvl(参数c,'一个在b中不可能出现的值')  
      

  4.   

    顶!
    select * from a where (参数c is not null and b=参数c) or (参数c is null and b is not null)
      

  5.   


    select b
      from a
     where (v_c is not null and b = v_c)
        or (v_c is null and b is not null)