decimal to hex conversion in sql server 2008

sql, sql-server-2008

Solution

SELECT CONVERT(VARBINARY(8), cast(2716455883 as bigint))

It is due to the way SQL Server interprets literals without qualified types. Check this out

select sql_variant_property(2716455883, 'basetype'); -- numeric
select sql_variant_property(2716455883, 'precision'); -- 10
select sql_variant_property(2716455883, 'scale'); -- 0

Problem

the hex value of `2716455883` is `A1E9D3CB` but using ``` SELECT CONVERT(VARBINARY(8), 2716455883) ``` getting answer `0x0A000001CBD3E9A1`

Original source