Search code examples
sqlchecksum

Checksum for datetime field in SQL


Task: We are validating the data in 2 different tables (of same structure). We tried to use the checksum function on the records for this.

Problem: The records in the table are same. But when we use the checksum(*), it gives different CheckSum.

SELECT statusName,CheckSum(*) from OrderStatus

If i calculate the checksum, excluding the DateTime column, it gives the same value in both tables.

SELECT statusName,CheckSum(StatusName,CreatedByUser,ModifiedByUser) from OrderStatus

Columns in Tables: StatusName,CreatedByUser,ModifiedByUser,CreatedDateTime,LastModifiedTime

How to resolve this, by including the datetime column.

Any help is appreciated!!!!


Solution

  • For a checksum, the order of the columns makes a difference.

    Replace the * in the first query with the exact same list of columns. CheckSum should work on date and datetimes.