1. 程式人生 > >SQL Server Binary轉換

SQL Server Binary轉換

DECLARE @hexstring VARCHAR(MAX)='E0F0C0';
SELECT CAST('' AS XML).value('xs:hexBinary(substring(sql:variable("@hexstring"), sql:column("t.pos")) )', 'VARBINARY(MAX)')
FROM (SELECT CASE SUBSTRING(@hexstring, 1, 2) WHEN '0x' THEN 3 ELSE 0 END) AS t(pos)