0

I have a table with a column data type nvarchar(max), the column will have data more than 8000 characters.

mytext navarchar(max)

I want to calculate hash value of that column, I am using the following code in MS SQL 2008/R2

select HASHBYTES('md5',column_name)

But I am getting error as,

String or binary data would be truncated.

Is that possible to calculate hash value in nvarchar(max) field in sql query.

Or is there any other ways to do it.

Thanks in advance.

Magendran V
  • 1,411
  • 3
  • 19
  • 33
  • 1
    MSDN Documentation for [`HASHBYTES`](https://msdn.microsoft.com/en-us/library/ms174415(v=sql.105).aspx), says `Allowed input values are limited to 8000 bytes` hence sorry you are out of luck :) – M.Ali Aug 19 '15 at 14:34
  • 3
    possible duplicate of [SQL Server 2008 and HashBytes](http://stackoverflow.com/questions/3717977/sql-server-2008-and-hashbytes) – Evaldas Buinauskas Aug 19 '15 at 14:35
  • With a .Net CLR, it works fine with long string – Julien Vavasseur Aug 19 '15 at 15:07

1 Answers1

1

Allowed input values are limited to 8000 bytes as was mentioned.

Try:

select master.sys.fn_repl_hash_binary(cast(column_name as varbinary(max)))

For this operation you have to disable FIPS validated cryptographic algorithms: http://blog.aggregatedintelligence.com/2007/10/fips-validated-cryptographic-algorithms.html