select isnull(a.dtdate,b.dtdate) as dtdate,
       a.mReceipt,
       b.mpay, 
       (isnull(a.mReceipt,0)-isnull(b.mpay,)) as mreplus,
       isnull(a.neptpk,b.neptpk) as ndeptpk
from table1 a full join table2 b on a.nDeptPK=b.nDeptPK and  a.dtDate=b.dtDate
group by isnull(a.dtdate,b.dtdate),isnull(a.neptpk,b.neptpk)

解决方案 »

  1.   

    create view v_t1_t2
    as
    select isnull(a.dtdate,b.dtdate) as dtdate,
           a.mReceipt,
           b.mpay, 
           (isnull(a.mReceipt,0)-isnull(b.mpay,)) as mreplus,
           isnull(a.neptpk,b.neptpk) as ndeptpk
    from table1 a full join table2 b on a.nDeptPK=b.nDeptPK and  a.dtDate=b.dtDate
    group by isnull(a.dtdate,b.dtdate),isnull(a.neptpk,b.neptpk)
      

  2.   

    错误:
    服务器: 消息 8120,级别 16,状态 1,行 8
    列 'b.mMoney' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
    服务器: 消息 8120,级别 16,状态 1,行 8
    列 ' a.mPay'在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
      

  3.   

    create view v_t1_t2
    as
    select isnull(a.dtdate,b.dtdate) as dtdate,
           a.mReceipt,
           b.mpay, 
           (isnull(a.mReceipt,0)-isnull(b.mpay,)) as mreplus,
           isnull(a.neptpk,b.neptpk) as ndeptpk
    from table1 a full join table2 b on a.nDeptPK=b.nDeptPK and  a.dtDate=b.dtDate
    去掉  group  by  那一行