Solved

Record bit comparison

Posted on 2009-05-07
6
420 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
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

772 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