[英]delete column from one table created while joining two tables using inner join
I have two temptables joined by using innerjoin and code as follows 我有两个临时表通过使用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
Now output is as follows 现在输出如下
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
How to remove the vendor number which is repeated twice can any one help? 如何删除重复两次的供应商编号可以帮助一个人?
in the last select 在最后选择
Insetead of select * from .... 选择* from ...的方法。
select only the columns you need eg: 只选择您需要的列,例如:
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.