|
jhocutt
Constraint Violating Yak Guru
385 Posts |
Posted - 2008-10-17 : 16:36:15
|
| [code]-- Bulk Load the Excel into a temp table with the same structure.-- Then do the compare using the primary key to join the tables-- This is your originalcreate table #DB ( pk int, c1 varchar(50), c2 varchar(50), c3 varchar(50))insert into #DB select 1, 'Hello', 'World', 1 union all select 2, 'Hello', 'My World', 2 union all select 3, 'Hello', 'Your World', 3 union all select 4, 'Hello', 'A World', 4 union all select 5, 'Hello', 'Some World', 5 -- This is your XLScreate table #XLS ( pk int, c1 varchar(50), c2 varchar(50), c3 varchar(50))insert into #XLS select 1, 'Hello', 'World', 2 union all -- Different select 2, 'Hello', 'My World', 2 union all select 3, 'Hello', 'Your own World', 3 union all -- different select 4, 'Hello', 'A World', 4 union all select 5, 'Hello', 'Some World', 5 -- select * from #DB-- select * from #XLSselect * from (select #DB.*, 'SAME' compare from #DB left JOIN #XLS on #DB.pk=#XLS.PK WHERE #DB.c1=#XLS.c1 AND #DB.c2=#XLS.c2 AND #DB.c3=#XLS.c3union allselect #DB.*, 'DIFFERENT' compare from #DB left JOIN #XLS on #DB.pk=#XLS.PK WHERE (#DB.c1<>#XLS.c1 OR #DB.c2<>#XLS.c2 OR #DB.c3<>#XLS.c3)) a ORDER BY a.pkdrop table #DBdrop table #XLS[/code]"God does not play dice" -- Albert Einstein"Not only does God play dice, but he sometimes throws them where they cannot be seen." -- Stephen Hawking |
 |
|