Dain_Anderson,
In fact you don't even need the cast to varbinary as this can be done implicitly:
Select Replace(master.dbo.fn_varb
Tim
Main Topics
Browse All TopicsHello Experts,
I've got a column of "float" datatype, and I am wanting to convert the data into Hexadecimal on-the-fly for output.
For example, my value of 1595833113 (float) would result in 5F1E7B19. In mySQL, I can use the Hex() function -- is there an equivalent in MSSQL 2000? If not, what are the steps required to get the data in Hex format? I've attempted many differnt combinations of Cast() with no luck.
Thanks for the help,
-Dain
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi Tim,
I think I'm getting close, but it's my lack of knowledge that's causing the issue here.
Your SQL returns:
41d7c79ec6400000 (or 0x41d7c79ec6400000 without the Replace() function) for the float value of 1595833113.
If I enter the value of 1595833113 into a sceintific calculator, and click the Hex option, the value returned is 5F1E7B19, which is what I'm trying to get in my output. I'm at a loss on this one -- any ideas?
Thanks you so much for replying,
-Dain
Dain_Anderson,
Very strange, when I run it it gives me 0x5f1e7b19 as expected. My fault I guess, I just used a static value of 1595833113 instead of casting it to a float. If it is a float then it gives the hex value you show. However casting this to int seems to work:
Compare the results of:
Select Replace(master.dbo.fn_varb
with
Select Replace(master.dbo.fn_varb
Tim
Hi Tim,
For some reason, it's not treating the column value of 1595833113 as static, so when I run the CAST as int, it throws an error:
Arithmetic overflow error for type int, value = 3972869579.000000
If I hard-code the 1595833113 value in the SQL statement, all is fine, but when I use the value stored in the column, it won't cast to integer:
Replace(master.dbo.fn_varb
-Dain
Business Accounts
Answer for Membership
by: TimCotteePosted on 2006-09-21 at 04:51:15ID: 17568213
Hi Dain_Anderson,
intohexstr (cast(1595 833113 as varbinary)),'0x','')
Select Replace(master.dbo.fn_varb
Will get you a varchar containing the hex value from the float.
Tim Cottee