select isnull(a.id,b.id) as id,...
...

解决方案 »

  1.   

    select b.id, a.date, b.quantity  from  a left join b on a.date = b.date
      

  2.   

    select b.id, a.date, b.quantity  from  a left join b on a.date = b.date或者select  b.id, a.date, b.quantity  from  a ,b where a.date = b.date
      

  3.   

    --建立测试环境
    Create Table A(Date Varchar(10))
    Create Table B(id Int,Date Varchar(10),quantity Int)
    --插入数据
    Insert A Values('2005-5-8')
    Insert A Values('2005-5-9')
    Insert A Values('2005-5-10')
    Insert A Values('2005-5-11')
    Insert A Values('2005-5-12')Insert B Values(1,        '2005-5-9' ,      10)
    Insert B Values(1,        '2005-5-10',      20)
    Insert B Values(2,        '2005-5-11',      12)
    Insert B Values(2,        '2005-5-12',      11)
    --测试
    Select IsNull(B.id,1) As id,IsNull(B.date,A.date) As date,quantity from A Left Join B On A.date=B.date And id=1
    Union All
    Select IsNull(B.id,2),IsNull(B.date,A.date),quantity from A Left Join B On A.date=B.date And id=2
    --删除测试环境
    Drop Table A,B
    --结果
    /*
    id date quantity
    1 2005-5-8 NULL
    1 2005-5-9 10
    1 2005-5-10 20
    1 2005-5-11 NULL
    1 2005-5-12 NULL
    2 2005-5-8 NULL
    2 2005-5-9 NULL
    2 2005-5-10 NULL
    2 2005-5-11 12
    2 2005-5-12 11
    */