HashBytes

  • I need to hash a text data type column (MD5) in my database.  Unfortunately the HashByte function only takes in varchar and not a text data type.

    Anyone have any ideas how to get round this problem?

    thanks

  • varchar in 2005 takes unlimited size ( check out BOL ) change your text to varchar. You'll want to test against other issues ( if any ) first though.

    [font="Comic Sans MS"]The GrumpyOldDBA[/font]
    www.grumpyolddba.co.uk
    http://sqlblogcasts.com/blogs/grumpyolddba/

  • I've tried converting it to a varchar(max) in 2005, but with no success as some of the data is lost as the string is truncated.

  • The code below generates the following error (where the field name plantext has a text data type):

    "String or binary data would be truncated."

     

    DECLARE @hash varchar(45)

    DECLARE @plantext varchar(max)

    SELECT

    @plantext= CONVERT(varchar(max), plantext)

    FROM ustructplanstext

    WHERE plid = @plid

     

    SET @hash = HashBytes('MD5', @plantext)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply