Converting from hex string to varbinary and vice versa

Converting hexadecimal values to varbinary and vice versa is now easier using the XQuery functionality available from SQL Server 2005. The code samples below show how to perform the conversion(s): — Convert hexstring value in a variable to varbinary: declare @hexstring varchar(max); set @hexstring = ‘abcedf012439’; select cast(” as xml).value(‘xs:hexBinary( substring(sql:variable("@hexstring"), sql:column("t.pos")) )’, ‘varbinary(max)’) from…

5