2

我对ETL相当陌生。我正在研究这个过程,它的作用是加载人们的生日。这是从事实表加载到另一个表中的。没有键可以连接它们,涉及的所有三个表。我将拆分名称字段并与拆分名称匹配。这会加载匹配的,但我的问题是我必须将不匹配的加载到不同的第三个表中。我该怎么做这个逻辑?

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
4

2 回答 2

1

使用MERGE语句(参见示例D. 将 MERGE 语句的结果插入另一个表),您应该能够将 ETL 过程简单地放入单个语句中。

于 2012-11-08T15:40:33.340 回答
0
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;
于 2012-11-14T17:04:25.277 回答