[英]ETL SQL Server 2008 - How to handle non-matching records?
I am fairly new to ETL. 我是ETL的新手。 I am working on this proc and what it does is it loads birthdates of people.
我正在研究此proc,它的作用是加载人们的生日。 This is loaded from a fact table onto a different table.
这是从事实表加载到另一个表的。 There is no key to join them by, all the three tables involved.
涉及的所有三个表并没有加入它们的键。 I am going to split the Name field and do match with the split name.
我将拆分“名称”字段,并与拆分的名称匹配。 This loads the matching ones, but my question is I have to load the non matching ones to a different third table.
这将加载匹配的表,但是我的问题是我必须将不匹配的表加载到另一个第三表。 How do I do that logic?
我该怎么做?
update FactTableEmp F
set Bdate = S.Birthdate
from FactTableEmp
cross apply dbo.split(Name) as u
join SourceTableEmp S on u.Fname = s.FirstName and u.LName = S.Lastname
--Is using the one below going to work using the same way above?
u.Fnames != S.FirstName
u.Lname != S.Lastname
使用MERGE语句(请参见示例D.将MERGE语句的结果插入到另一个表中 ),您应该能够将ETL流程简化为单个语句。
INSERT dbo.third_table
SELECT Bdate, Name
FROM (
MERGE dbo.FactTableEmp AS target
USING (
SELECT x.Bdate,
x.Name,
u.FName,
u.LName,
s.Birthdate,
s.FirstName,
s.LastName
FROM dbo.FactTableEmp x CROSS APPLY dbo.split(x.Name) u
FULL JOIN dbo.SourceTableEmp s ON u.FName = s.FirstName and u.LName = S.Lastname
) AS source
ON (target.Name = source.Name AND source.FName = source.FirstName AND source.LName = source.Lastname)
WHEN MATCHED
THEN UPDATE SET target.Bdate = source.Birthdate
WHEN NOT MATCHED BY SOURCE
THEN UPDATE SET target.Name = target.Name
OUTPUT INSERTED.Bdate, INSERTED.Name) AS Changes(Bdate, Name)
WHERE Bdate IS NULL;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.