• Tom.Thomson (4/26/2011)


    wta306 (4/25/2011)


    How do you determine what size to make your VARBINARY field to hold the results of the HASHBYTES function?

    Is it simply a matter of setting it to be equal to the largest HashByte function input value?

    DECLARE @vHashResults AS VARBINARY(40)

    DECLARE @vHashInput01 AS CHAR(20)

    DECLARE @vHashInput02 AS CHAR(20)

    SET @vHashInput01 = 'thisisa20bytechar123'

    SET @vHashInput02 = 'thisisa21bytechar1234'

    SET @vHashResults = HashBytes('SHA1', @vHashInput01 + @vHashInput02)

    I would be somewhat horrified if HashBytes('SHA1', <anything>) delived a result with any length other than 160 bits (20 bytes)! That's what MS thinks it delivers too, according to BoL.

    Tom - thank you for the response.

    Unless I'm mistaken, MD5 is only 128 bits (16bytes)...and yet the author of the original article stores the resulting values in a VARBINARY(100)? What am I missing?