Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: 268 | Views in the last 30 days: 2
 
Related Articles
FORUM

Checksum function???

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

BLOG

SSIS – CHECKSUM Transformation

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

FORUM

checksums and unicode data

Same checksum value for two different values.

FORUM

How to Use BINARY_CHECKSUM operation.

BINARY_CHECKSUM

BLOG

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......

Tags
miscellaneous    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones