I have source data that is formatted as hexadecimal ASCII. I need to get it into the SQL database in the VARBINARY fields. I minimized the problem to illustrate what I would like to do. I have a stored procedure:
CREATE PROCEDURE BinaryDemo @BinaryData varbinary(max) AS BEGIN PRINT @BinaryData; END
I know that it "works" because I can do:
DECLARE @tmp varbinary(max); SET @tmp = CONVERT(varbinary, '1234567890abcdef', 2); EXEC BinaryDemo @ BinaryData=@tmp ;
What I would like to do is skip the intermediate steps and call a procedure like:
EXEC BinaryDemo @BinaryData=CONVERT(varbinary, '1234567890abcdef', 2);
Unfortunately, SQL complains about the syntax: Incorrect syntax next to the keyword 'CONVERT'.
I know that CONVERT is correct because I can:
PRINT CONVERT(varbinary, '1234567890abcdef', 2);
and I see exactly what I expect. The first example (declare / set / exec) is really a bad option due to the nature and amount of the source data.
source share