I've got two datatables (A, B) with the same structure. I need to compare each row of A with that of B and the resultant Datatable C should have the row in A and the changes of that row in B below it. For rows which are identical (same values in A & B) the resulting Datatable shouldn't have these rows.
So the resulting Datatable should have each row in A and its non-identical row in B under it. Resulting table shouldn't have identical rows.
Can anyone please help me with C# code.
the easiest way is a cross-database union:
create table merged
(select * from db1.t) union (select * from db2.t)
only unique rows are returned. to compare records, select rows that share the same key (the key column in merged will be non-unique).
select * from merged order by key
orders the results in the order you wanted.
select * from merged where key in
(select key from merged group by key having count(*) > 1)
order by key
will return only mismatched rows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With