2017-02-11 65 views
0

我想联同全外侧的两个临时表加入,但不能正常工作 和八方通只显示#RMS值,而不#RMB!连接两个临时表采用全外连接

那里的,什么是错误的代码?

(无空#RMS)

create table #RMS 
(
    [Year] int, 
    [Month] int, 
    sTAccount bigint, 
    sRemaining bigint 
) 
insert into #RMS(Year,Month,sTAccount,sRemaining) 
select 
    YEAR(Date) [Year], 
    DATEPART(MONTH,Date) [Month], 
    sum(TAccount) sTAccount, 
    sum(Remaining) sRemaining 
from 
    SaleInvoices 
group by YEAR(Date),DATEPART(MONTH,Date) 
order by YEAR(Date),DATEPART(MONTH,Date) 

(#RMB没有空,但有时#RMB月列值和#RMS月份列值是不同的)

create table #RMB 
(
    [Year] int, 
    [Month] int, 
    bTAccount bigint, 
    bRemaining bigint 
) 
insert into #RMB(Year,Month,bTAccount,bRemaining) 
select 
    YEAR(Date) [Year], 
    DATEPART(MONTH,Date) [Month], 
    sum(TAccount) bTAccount, 
    sum(Remaining) bRemaining 
from 
    BuyInvoices 
group by YEAR(Date),DATEPART(MONTH,Date) 
order by YEAR(Date),DATEPART(MONTH,Date) 

select * from #RMS 
Full Outer Join #RMB 
on #RMS.Year=#RMB.Year and #RMS.Month=#RMB.Month 
group by #RMS.Year, #RMS.Month 
order by #RMS.Year, #RMS.Month 

谢谢您的回答

回答

0

你认错SELECT列表。更换*#RMS.*, #RMB.*或(更好),你想要的字段的显式列表,前缀他们的名字与他们来自表的名称。这也使不重复你已经加入了对领域。