SQL Clone
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
SSC-Enthusiastic
SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)SSC-Enthusiastic (142 reputation)

Group: General Forum Members
Points: 142 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 (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: Administrators
Points: 12729 Visits: 24
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
SSC Eights!
SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)

Group: General Forum Members
Points: 924 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 Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 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
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4211 Visits: 8444
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
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

Group: General Forum Members
Points: 1436 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 (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)SSC-Enthusiastic (160 reputation)

Group: General Forum Members
Points: 160 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
SSC-Enthusiastic
SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)

Group: General Forum Members
Points: 115 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