• vk-kirov (2/1/2010)


    Hugo Kornelis (2/1/2010)


    the result of the HASHBYTES algorithm now exceeds 8000 bytes

    No, it doesn't 🙂 The SHA-1 algorithm always produces 160-bit output, here is the proof: http://en.wikipedia.org/wiki/SHA#Comparison_of_SHA_functions.

    The warning is raised because allowed input values for the HASHBYTES function are limited to 8000 bytes (http://msdn.microsoft.com/en-us/library/ms174415.aspx). I consider this as some strange obsolete limitation which can hardly be explained for MSSQL 2005 & 2008.

    You are absolutely right, and my explanation is incorrect.

    SELECT HASHBYTES('SHA1', REPLICATE(CAST('A' AS varchar(max)), 8000)) returns a 20-byte value, and SELECT HASHBYTES('SHA1', REPLICATE(CAST('A' AS varchar(max)), 9000)) returns the same warning message and no value. Why the IF comparison between the two doesn't abort but chooses to execute the ELSE clause is, in all honesty, beyond me. I firsth thought it was because the too-long input causes the function to return NULL (in addition to the message), but when I use IF HASHBYTES(...) IS NULL, I still got the "no" result.

    Anyhoo, I stand corrected. The HASHBYTES does apparently indeed have an (undocumented!!) limit of 8000 bytes on it's input string. Thanks for pointing that out!


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/