SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Script To Compute Checksum Of The Text Field

By blind-monkey,

It is a known fact, that checksum function can not be applied to text, ntext and image fields. But sometimes it is necessary to compare whether a value in a text field has changed (although it is not guaranteed that checksum generates a unique value, but it still could be used as a good estimator). This script computes checksum of the text field (has not been tested with ntext or images!). I think someone might find it useful. The only concern is that it does not perform greatly on the large strings (>1MB). Relatively small strings would provide a tolerable performance. But if one has to compare rows of the table field by field using checksums, text fields do not have to be excluded or truncated. The idea behind the function is very simple. It breaks text into chunks of 2000 characters (using substring(…) function). Then it records every chunk of text into a table variable. Identity field of the table variable will maintain correct order of every portion of data. After data splitting is complete, one can compute an aggregate checksum on the table variable using checksum_agg(binary_checksum(*)) expression. This expression is described in SQL Server BOL.

Total article views: 294 | Views in the last 30 days: 1
Related Articles

Checksum function???

How to use Checksum function to compare million records...


SSIS – CHECKSUM Transformation

CHECKSUM is a TSQL function that computes a hash value over a list of arguments.  The great thing ab...


checksums and unicode data

Same checksum value for two different values.


How to Use BINARY_CHECKSUM operation.



Using Checksum in SSIS for Delta Loads

The checksum function in SQL is a great way to compare two rows to see if the data matches. The......