Convert HEX to BIGINT
SQL Server 2000: Tested
SQL Server 2005: Tested
SQL Server 2008: Tested
SQL Server 2008R2: Tested
SQL Server 2012: Tested
Author: Various (incl. Pinal Dave and the original 2000/5 from PDreyer
Date: 9 Jul 2008
When I went to publish this tip, I looked at the code i had stored and something didn't seem quite right. It had become corrupted over the years. I searched out a much better function-based version which is published below and is valid for all versions of SQL Server.
However, from SQL 2008 onwards, the CAST/CONVERT functions are able to perform this conversion directly, with the HEX represented as either a VARBINARY token, or a HEX character string with or without the '0x' prefix.
-- FOR SQL 2000/2005 (and 2008/12 if required)
-- for SQL 2008 , 2008R2, 2012