我试图比较我的DM层中的两个表,但来自两个不同的数据库(旧数据库和新数据库,用于数据一致性/比较数据分析)。为了能够比较我需要通过EDW和MDM / Maps层加入的两个表。我需要比较列和行以匹配内容,并且我希望以某种方式输出不匹配的内容。你会如何处理这个?
到目前为止,我有这个Full外连接。我正在考虑使用这种比较不等式的方法:http://weblogs.sqlteam.com/jeffs/archive/2004/11/10/2737.aspx
但我似乎无法让我的UNION ALL工作而不是FULL OUTER JOIN。你将如何继续,你会使用UNION ALL吗?
USE Northwind ;
GO
SELECT c.*, o.*
FROM Northwind.dbo.Customers AS c
INNER JOIN OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb';'admin';'', Orders)
AS o
ON c.CustomerID = o.CustomerID ;
GO
答案 0 :(得分:0)
此查询显示OLD中存在的所有行,并在NEW中显示:
select dm.*, mdm.ProductionSystem, mdm.SchoolIdent
from DM_OLD.dbo.DimSchool dm
inner join EDW_OLD.dbo.School edw on dm.EdwSchoolId = edw.SchoolID
inner join MDM_OLD.dbo.School mdm on edw.SYS_BusinessKeyFK = mdm.SYS_BusinessKeyID
except
select dm.*, maps.ProductionSystem, maps.SchoolIdent
from dm.dbo.DimSchool dm
inner join edw.dbo.School edw on dm.EdwSchoolId = edw.SchoolID
inner join edw.maps.School maps on edw.SYS_BusinessKeyFK = maps.SYS_BusinessKeyID
这将向您展示您在OLD中所拥有的新东西:
select dm.*, maps.ProductionSystem, maps.SchoolIdent
from dm.dbo.DimSchool dm
inner join edw.dbo.School edw on dm.EdwSchoolId = edw.SchoolID
inner join edw.maps.School maps on edw.SYS_BusinessKeyFK = maps.SYS_BusinessKeyID
except
select dm.*, mdm.ProductionSystem, mdm.SchoolIdent
from DM_OLD.dbo.DimSchool dm
inner join EDW_OLD.dbo.School edw on dm.EdwSchoolId = edw.SchoolID
inner join MDM_OLD.dbo.School mdm on edw.SYS_BusinessKeyFK = mdm.SYS_BusinessKeyID