Solved

Record bit comparison

Posted on 2009-05-07
6
431 Views
Last Modified: 2012-05-06
Is there a way to compare two records to determine if any of the fields contain different values WITHOUT having to compare each and every field? Something like a bit comparison between each record?

I need to compare employee data from a thrid party program which is downloaded each week against the current data. I need to determine if data in any field is different and if so write the old record to the archive table and insert the 3rd party record to the current table.  There are about 100 fields and I would love to be able to compare it without having to write out every field.

Thanks - Charlie
0
Comment
Question by:CLoprinzo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24326440
How refined should it be? Say, you've John Smith in your table and JohnSmith in the 3rd party table. How do you want to deal that?
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24326457
you can do it...sure.  you can do something like this (you'll need to add a computed column)

alter table tablename
add bitmask as binary_checksum(field1, field2, field3, ...)

then, you can just run sql queries to compare the new bitmask field to the bitmask of other records to tell if they are the same.  There is a possibility of collisions (diferrent values hashing to be the same value over a set of fields), but it is unlikely.
0
 
LVL 1

Author Comment

by:CLoprinzo
ID: 24326921
Basically I need to determine if any field has changed (Employment Status, Marital Status, pay rate, address, etc.) and if so I want to insert the record into tblEmployeeDetail _Archive and delete it from the tblEmployeeDetail , then insert the downloaded one into tblEmployeeDetail.

chapmandew - I am not familiar with binary_checksum... it will only work on altered records in a table correct? or am I reading it wrong?  I need to compare record ABC from tblEmployeeDetail to ABC from
the downloaded table.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Accepted Solution

by:
chapmandew earned 250 total points
ID: 24326942
add the computed column to both tables (with same defintion), and compare the records

--this will give you the records that have been updated...
select * from tbl_employeedetail d join tbl_employeedetail_archive a
on d.primarykey = a.primarykey
where a.bitmask <> d.bitmask
0
 
LVL 1

Author Closing Comment

by:CLoprinzo
ID: 31579023
Your rank says it all ... Genius!

That worked exactly the way I wanted and it's pretty fast too!!  Thanks a million!!
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24327923
Well I really appreciate that.  Glad to help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Conditions in Where clause 9 46
Can I skip a node in XML? 9 31
T-SQL Query - Group By Year 3 28
SQL Query Across Multiple Tables - Help 5 12
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question