Compare two tables

  • Hi,

    I need to compare data in the same table from two different databases.

    AdeptSQL Diff does a good job but does not have capabilities to export

    the results. I need to present the comparison results to the user.

    I am trying to write a stored procedure to do a comparison

    and store the results in a third table

    but it might take time.

    Has anybody seen maybe a script to do the comparison?

    Thanks,

    Robert

  • have you tried RedGate SQL Compare?



    A.J.
    DBA with an attitude

  • I did try Red-Gate.

    I couldn't save the results in CSV or any other format.

    After I played with it for an hour I gave up.

  • What exacatly you mean with compare? Do you want to show to the user doubble records or a total of maching records (like same client code or ID)?

    For example finding duplicated Codes in the two tables:

    SELECT DB1.dbo.Table1.Code, DB1.dbo.Table1.ID, DB1.dbo.Table1.Name

    FROM DB1.dbo.Table1

    WHERE DB1.dbo.Table1.Code In (SELECT DB2.dbo.Code FROM DB2.dbo.Table1 GROUP BY DB2.dbo.Code HAVING Count(*)>1 )

    ORDER BY DB1.dbo.Table1.Code

    Enter this statement as Stored Procedure in any of the two DB's. You can query any tables from any DB like the one above.

    I hope this helpes.

  • Sorry, the select statement I just sent before is to find duplicated records in one table; was stupid.

    But the basic what I mean is that you can query tables from different DB's without any problem.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply