Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

HashBytes Function - Change varbinary output Expand / Collapse
Author
Message
Posted Tuesday, May 30, 2006 9:52 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 15, 2006 4:04 PM
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.

 

Post #283636
Posted Friday, June 2, 2006 8:00 AM
SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, May 18, 2007 3:36 PM
Points: 10,039, 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!
Post #284547
Posted Monday, March 26, 2007 3:10 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, May 8, 2014 10:08 PM
Points: 358, Visits: 397

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

Post #353786
Posted Tuesday, November 27, 2007 9:35 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, September 18, 2014 9:50 AM
Points: 116, Visits: 363
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.
Post #426463
Posted Wednesday, November 28, 2007 5:26 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, September 18, 2014 4:53 AM
Points: 848, Visits: 5,507
Try casting to bigint and using the fnNumber2AnyBase function at the following link.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=87871
Post #426830
Posted Monday, December 3, 2007 8:28 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, March 6, 2014 6:13 PM
Points: 318, Visits: 1,183
Also check out http://support.microsoft.com/kb/104829 for the (slightly old but still valid) Microsoft function.
Post #429090
Posted Sunday, February 24, 2008 8:55 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 12:42 PM
Points: 104, Visits: 126
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)
Post #459512
Posted Tuesday, April 2, 2013 1:51 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, June 25, 2013 12:32 AM
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
Post #1438075
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse