Convert BINARY saved as VARCHAR to BINARY

I am making INSERT SELECTfrom a table (source) where each column has a data type VARCHAR.

One of the columns stores binary data, such as

'0003f80075177fe6'

The destination table into which I insert this has the same column, but with the corresponding data type BINARY(16).

INSERT INTO destination
(
    column1,        --type of BINARY(16)
    ...
)
SELECT
    CONVERT(BINARY(16),[varchar_column_storing_binary_data]),   --'0003f80075177fe6'
FROM source
GO

When I insert it, then select the destination table, I got another value from the column BINARY16:

0x30303033663830303735313737666536

Actually this does not seem to be the same meaning.

What should be the correct way to convert binary data stored in column VARCHARto BINARY?

+4
source share
1 answer

, "0003f80075177fe6" ( VARCHAR) , . , , , ASCII, , ASCII: 0 - 48 (30 hex), f - 102 (66 hex) .. 30 30 30 33 66 38 30 30...

(00 03 f8 00 75 71 77 fe 66). CONVERT "style", hexstrings:

SELECT CONVERT(BINARY(16), '0003f80075177fe6', 2)

2 . ( 1 , "0x", .)

, 16 ( ), (0x0003F80075177FE60000000000000000). , :

SELECT CONVERT(BINARY(16), RIGHT(REPLICATE('00', 16) + '0003f80075177fe6', 32), 2)

, , , "0x" : SELECT 0x0003f80075177fe6 BINARY(8). , .

+7

All Articles