Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 compare 2 results and save unmatched records

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2012-12-25 : 13:49:32
Hi there,

I have table1 which has some raw data processed and saved in table2. Now I need to compare the data from these 2 tables by running different stored procedures, to see if they match. If yes then pass, if not then save the error and the different results fom comparison. I run exec sp1 param1, param2 to get results from table2 and runn exec sp2 parameter1, parameter2 ... to get results from table2. The results columns could be different, see follwoing: but the bold ones are the ones to be compared:

result1: ...ID, Code, Model, Num, ... Date
result2: ...ID, Name, Model, SerialNum, Date

Model and Date must be compared and if they're not match then I need save the ID and different values for Model and Date, in a third table. How can I do this? Thanks in advance and Merry Christmas!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-25 : 23:51:03
you'll need temporary tables for that. Create two temporary tables to store sp result and then use it to compare Model and Date fields. use INSERT...EXEC statement to populate table with SP results. The table structure should be same as SP resultset

Another approach is below which is not recommended as it makes use of distributed query

http://beyondrelational.com/modules/2/blogs/70/posts/10812/select-columns-from-exec-procedurename-is-this-possible.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -