?
Solved

Record bit comparison

Posted on 2009-05-07
6
Medium Priority
?
468 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
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!

 
LVL 60

Accepted Solution

by:
chapmandew earned 1000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

649 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