Solved

Record bit comparison

Posted on 2009-05-07
6
387 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sql query 7 34
SQL JOIN 6 31
search for a string in all tables 4 15
Test a query 23 11
In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now