如果表1的id不为空则where 表1.id=表2.id and 另外条件,如果表1的id为空则where 另外条件;现在我并在一起:where 表2.id=isnull(表1.id,表2.id),查询不成功不知道问题出在哪里?

解决方案 »

  1.   

    where (case when 表1.id is null then 表1.id=表2.id else 1=1 end) 
      

  2.   

    -- 这样写就行啦:
    where t1.id=t2.id  -- 此时不需要考虑空值:因为空值与空值相比较,为假(两个空值不相等)
    or  ( t1.id is null and 其他条件);-- or 表示:并在一起
      

  3.   

    where 表2.id=isnull(表1.id,表2.id)
    应该是这样的。
      

  4.   


    where (case when 表1.id is not null then 表1.id=表2.id else 1=1 end)
      

  5.   

    isnull是sql server的语法
    oracle的用nvl楼主可以把当“如果表1的id为空则where 另外条件”中的另外的条件也给出来
    大家可以给你更完整的答案
      

  6.   

    where 表2.id=nvl(表1.id,表2.id)
      

  7.   

    表1.id
    where (表1.id=表2.id) or (表1.id is null and ....)感觉你的完全就是外连接
    表1.id(+)=表2.id