Passing VARBINARY to a stored procedure

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.

+4
source share
1 answer

good question.

but I think it is possible. its like:

works good:

  DECLARE @r DATETIME SET @r=GETDATE() EXEC [dbo].[sp_myDatePrinter] @ d=@r 

bad:

 DECLARE @r DATETIME EXEC [dbo].[sp_myDatePrinter] @d=GETDATE(); 
+1
source

Source: https://habr.com/ru/post/1382359/


All Articles