Sample Header Ad - 728x90

Why does inserting a value into a temp table's BINARY(8) column cause an error when casting the same value to BINARY(8) does not?

0 votes
1 answer
244 views
When I execute this: DROP TABLE IF EXISTS #QueryHashes; CREATE TABLE #QueryHashes (query_hash BINARY(8) NOT NULL PRIMARY KEY); PRINT CAST(0x0169857CCD5BBBE4E AS BINARY(8)); -- just testing that the value is a legitimate BINARY(8) /* Insert your query_hash values inside the outer parenthesis below, each wrapped in parenthesis, comma-separated (for example, "(0x89E35F2D4C638298), (0x89E35F2D4C638298)") */ INSERT INTO #QueryHashes (query_hash) VALUES (0x0169857CCD5BBBE4E); PRINT CAST(0x0169857CCD5BBBE4E AS BINARY(8)); -- just testing that the value is a legitimate BINARY(8) I get this error: > 0x00169857CCD5BBBE Msg 2628, Level 16, State 1, Line 9 String or > binary data would be truncated in table > 'tempdb.dbo.#QueryHashes________________________________________________________________________________________________________000000000D06', column 'query_hash'. Truncated value: ''. The statement has been > terminated. 0x00169857CCD5BBBE Note that the value in the error message seems to be an empty string. Clearly, the insert is failing, while the casts work. Can anyone help me understand what is wrong with the insert or table definition? Even if I remove the "NOT NULL PRIMARY KEY", I still get the same error. (The eventual intent is to insert a few values into the table, and join it into a big query.)
Asked by Mark Freeman (2293 rep)
Nov 13, 2023, 06:12 PM
Last activity: Nov 13, 2023, 07:35 PM