繁体   English   中英

从使用内部联接联接两个表时创建的一个表中删除列

[英]delete column from one table created while joining two tables using inner join

我有两个临时表通过使用innerjoin和代码连接如下

IF OBJECT_ID('tempdb..#temp_table3') IS NOT NULL
    DROP TABLE #temp_table3

select VendorNumber,stuff( (select distinct ','+dbo.vendordata.InvoiceStatus
                               from dbo.vendordata
                               where dbo.vendordata.VendorNumber = dbo.vendordata.VendorNumber 
                               for xml path('')
                              ), 1, 1, ''
                            ) as InvoiceStatus
into #temp_table3
from dbo.vendordata
group by VendorNumber


IF OBJECT_ID('tempdb..#temp_table4') IS NOT NULL
    DROP TABLE #temp_table4

select VendorNumber, sum(EY_AmountIncl_LC) AmountIncl_LC,
       sum(EY_AmountExcl_LC) AmountExcl_LC, max(EY_datedocumented) Datedocumented
into #temp_table4
from dbo.vendordata
group by VendorNumber

select * 
from #temp_table3 T inner join 
     #temp_table4 V 
     on T.vendorNumber = V.VendorNumber

现在输出如下

VendorNumber  Invoicestatus      VendorNumber   EY_AmountIncl   EY_AmountExcl     EY_datedocumented
50000471     V-Parked S-Noted     50000471        281072           281072           00:00.0
5200991      V-Parked S-Noted     5200991         80000            80000            00:00.0
5200595      V-Parked S-Noted     5200595         72401.6         72401.6           00:00.0

如何删除重复两次的供应商编号可以帮助一个人?

在最后选择

选择* from ...的方法。

只选择您需要的列,例如:

select T.VendorNumber, T.InvoiceStatus, V.AmountIncl_LC, 
       V.AmountExcl_LC, V.Datedocumented
from #temp_table3 T inner join 
     #temp_table4 V 
     on T.vendorNumber = V.VendorNumber

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM