Welcome to San Francisco, Baghdad by the Bay

The blog, rants, ravings, and commentaries of Bill Watters

T-SQL: Hex String to Hex Value func

May 19th, 2008 · No Comments

SQL Server 2005 includes an undocumented function, sys.fn_varbintohexstr, that converts a hex value to a string representation of that hex value (0×3a becomes ‘0×3a’), but there is no function to go back from a hex string to a hex value. Below is something that does the trick quite nicely
CREATE FUNCTION dbo.HexStrToVarBin(@hexstr varchar(8000))
RETURNS varbinary(8000)
AS
BEGIN 
    DECLARE @hex char(2), @i [...]

[Read more →]

Tags: Programming