Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing Records in Tables

Status
Not open for further replies.

mydisney

Programmer
May 7, 2007
55
US
I have 2 tables that are identical. These tables are being replicated and should contain the same number of records and data etc. From time to time, for whatever reason, these tables get out of "sync".

Now, I need to compare compare records in the 2 tables. I have sql code that looks at both tables. The problem is that the output lists all the records.

At this point I am only interested in printing record(s) that exist in one table but not in the other. Can someone help?



Table 1, ODBC for RGWP Remote Server

SELECT "SALESTKT"."TICKET_ID", "SALESTKT"."TICKET_DATE", "SALESTKT"."TICKET_TIME" FROM "SALESTKT" "SALESTKT" EXTERNAL JOIN SALESTKT.TICKET_ID={?Advantage ODBC for RGWP: SALESTKT_1.TICKET_ID}


Table 2, ODBC for RGWP Local Server

SELECT "SALESTKT_1"."TICKET_ID", "SALESTKT_1"."TICKET_DATE", "SALESTKT_1"."TICKET_TIME" FROM "SALESTKT" "SALESTKT_1"
WHERE "SALESTKT_1"."TICKET_ID"={?Advantage ODBC for RGWP Remote: SALESTKT.TICKET_ID}

 
try doing something like:

Select "SALESTKT1"."TICKET_ID", "SALESTKT1"."TICKET_DATE1", "SALESTKT1"."TICKET_TIME" from table1 SALESKT1
where not exists
(select 1 from table2 SALESKT2 where "SALESTKT1"."TICKET_ID" = "SALESTKT2"."TICKET_ID"
and "SALESTKT1"."TICKET_DATE1"= "SALESTKT2"."TICKET_DATE1"
and "SALESTKT1"."TICKET_TIME" = "SALESTKT2"."TICKET_TIME"

union all

Select "SALESTKT2"."TICKET_ID", "SALESTKT2"."TICKET_DATE1", "SALESTKT2"."TICKET_TIME" from table2 SALESKT2
where not exists
(select 1 from table1 SALESKT1 where "SALESTKT2"."TICKET_ID" = "SALESTKT1"."TICKET_ID"
and "SALESTKT2"."TICKET_DATE1"= "SALESTKT1"."TICKET_DATE1"
and "SALESTKT2"."TICKET_TIME" = "SALESTKT1"."TICKET_TIME"

Its a bit primative but shoud bo the job


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top