SQL convert string data in hexadecimal format into string text

后端 未结 3 1923
夕颜
夕颜 2021-01-21 17:33

I have a table which has a column X. X will be storing large text values in hex format. Now I want to convert hex to raw and validate the data. But when I am using the below que

3条回答
  •  借酒劲吻你
    2021-01-21 17:55

    This can be done in SQL server using built-in conversions via varbinary data type.

    -- VARCHAR TO (HEX) VARCHAR
    SELECT CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), 'Help'), 1) -- '0x48656C70'
    
    -- (HEX) VARCHAR TO VARCHAR
    SELECT CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), '0x48656c70', 1)) -- 'Help' (requires 0x)
    SELECT CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), '48656c70', 2)) -- 'Help' (assumes 0x)
    

提交回复
热议问题