question

viki2015 avatar image
viki2015 asked

Converting Dec o Hex

I am trying to convert dec to Hex and using CONVERT(VARBINARY (1), [value]) but getting the output like 0x11 but wanted to show as 11 only. I know it is quite quick but not for me, can someone please help me to get this right.
sqlsql-server
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

perrywhittle avatar image
perrywhittle answered
this should get you what you require SELECT [sys].[fn_varbintohexsubstring](0, ( CONVERT (VARBINARY(1), value) ), 1, 1)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

viki2015 avatar image viki2015 commented ·
worked as charm, thanks
0 Likes 0 ·
vinaygr24 avatar image
vinaygr24 answered
Hi Viki try this method.. DECLARE @BinaryValue VARBINARY(256) SET @BinaryValue = 4524232 SELECT CONVERT([varchar](512), @BinaryValue, 1) Result: 0x004508C8 SELECT CONVERT([varchar](512), @BinaryValue, 2) Result: 004508C8
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.