我使用Lookup转换来比较来自不同服务器的两个表。我想在目标无匹配输出表中添加查找列值,如下所示。例如,表1是我的表,我需要检查坏数据。
ID | Name | Address
--------------------------
1 | Ramya | 01 - London
--------------------------
2 | Vidya | India
以下是我的查找表
ID | Name | Address
--------------------------
1 | Ramya | London
--------------------------
22 | Vidy | India
我希望我的目的地(另一个新表)拥有包含不匹配行的数据
ID | Name | Address | LID | LName | LAddress
---------------------------------------------------------
1 | Ramya | 01 - London | NULL | NULL | London
---------------------------------------------------------
22 | Vidy | India | 2 | Vidya | NULL
或类似的东西::
ID | Name | Address | Mismatch|
-------------------------------------
1 | Ramya | 01 - London | Address: London |
-------------------------------------
22 | Vidy | India | ID: 2 and Name: Vidya|
答案 0 :(得分:0)
您是否可以在SSIS中处理之前识别不匹配的记录。 这里有一些SQL来创建示例数据并提供匹配/非匹配记录。然后,SSIS可以处理不匹配的记录,并使用Name进行其他查找,以查看这些记录是否匹配。但是,这可能会有多个匹配!
create table #temp1(
id1 integer,MyName1 varchar(50),MYaddress1 varchar(50)
)
create table #temp2(id2 integer,MyName2 varchar(50),MYaddress2 varchar(50)
)
insert into #temp1 (id1,Myname1,myaddress1)
values (1,'Ramya','01 - London')
insert into #temp1 (id1,Myname1,myaddress1)
values (2,'Vidya','India')
select * from #temp1
insert into #temp2 (id2,Myname2,myaddress2)
values (1,'Ramya','London')
insert into #temp2 (id2,Myname2,myaddress2)
values (22,'Vidya','India')
select * from #temp2
;
with mycte1 as
(SELECT
a.id1,a.myName1,a.MyAddress1,b.id2,b.myName2 as LName,b.myAddress2 as LAddress,
'No Match' as Match
from #temp1 a left join #temp2 b
on a.myname1 = b.myname2 and
a.myAddress1 = b.myAddress2
where b.myaddress2 is null or b.myname2 is null
),
mycte2 as
(SELECT a.id1,a.myName1,a.MyAddress1,b.id2,b.myNAme2 as LName,
b.myAddress2 as LAddress,'Match' as Match
from #temp1 a inner join #temp2 b
on a.myname1 = b.myname2 and
a.myAddress1 = b.myAddress2
)
select * from mycte2
union
select * from mycte1
drop table #temp1
drop table #temp2