从两个源表插入一个目标表 [英] insert into one destination table from two source tables
问题描述
对于数据迁移,我需要比较两个源表的计数并在目标中生成结果"检查"。表格如下:
For data Migration, I need to compare the counts of two source tables and produce results in a destination "Check" table as follows:
表格类型 |      表1   |   表2
GL条目                 24116          28209
GL Entry 24116 28209
供应商                     1556          1556
Vendors 1556 1556
任何想法?
推荐答案
是同一台服务器上的两个来源吗?如果是,你可以简单地做
are two sources on same server? if yes you can simply do like
INSERT CheckTable
SELECT 'GL Entry',(SELECT COUNT(*) FROM GLEntry),(SELECT COUNT(*) FROM db2.dbo.GLEntry)
UNION ALL
SELECT 'Vendors',(SELECT COUNT(*) FROM Vendors),(SELECT COUNT(*) FROM db2.dbo.Vendors)
..
其中db2是第二个数据库的名称
where db2 is name of your second db
如果他们在不同的服务器上,您需要设置链接服务器或使用分布式查询方法,如OPENROWSET
If they're in different servers you would require setting up linked server or use distributed query methods like OPENROWSET
这篇关于从两个源表插入一个目标表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!