Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


HashBytes Function - Change varbinary output


HashBytes Function - Change varbinary output

Author
Message
dan9001
dan9001
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 1

DECLARE @HashThis varchar(255);
SELECT @HashThis = 'Hello world!'
SELECT HashBytes('MD5', @HashThis)

The default output is varbinary:
0x86FB269D190D2C85F6E0468CECA42A20

But I need it as char(32):
86FB269D190D2C85F6E0468CECA42A20

Does anyone know how to do this? I can't use the varbinary data type in my application. I can only use char(32) datatype. Thanks.


Site Owners
Site Owners
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10095 Visits: 1
No one has responded to this topic yet. Even if you don't have a complete answer, the original poster will appreciate any thoughts you have!
magarity kerns
magarity kerns
Old Hand
Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)Old Hand (384 reputation)

Group: General Forum Members
Points: 384 Visits: 397

Your original message is getting old; did you find that the answer is to use the master.dbo.fn_varbintohexstr function?


Codezilla-292868
Codezilla-292868
SSC-Enthusiastic
SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)

Group: General Forum Members
Points: 116 Visits: 400
Did you find an answer to this question? I am facing the same issue. I do not want to convert it to varbinary. I would like to use varchar instead.
Thanks in advance.
Ken McKelvey
Ken McKelvey
SSC Eights!
SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)

Group: General Forum Members
Points: 962 Visits: 7279
Try casting to bigint and using the fnNumber2AnyBase function at the following link.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=87871
Jacob Luebbers
Jacob Luebbers
Old Hand
Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)

Group: General Forum Members
Points: 330 Visits: 1215
Also check out http://support.microsoft.com/kb/104829 for the (slightly old but still valid) Microsoft function.
Lee Fisher
Lee Fisher
SSC-Enthusiastic
SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)SSC-Enthusiastic (108 reputation)

Group: General Forum Members
Points: 108 Visits: 160
There is an undocumented function that will help

DECLARE @HashThis varchar(255);
SELECT @HashThis = 'Hello world!'
SELECT HashBytes('MD5', @HashThis)
SELECT SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', @HashThis)), 3, 32)
mimran18
mimran18
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 259
You can convert hashbytes to varchar through XQuery as well.

Here is the solution. http://raresql.com/2013/04/02/sql-server-how-to-convert-hashbytes-to-varchar/

MI
http://raresql.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search