Variable Out, Error

1

Hi, I want to create a variable OUT that I will use later, but the following error appears when creating the block:

DECLARE
@COD_PERI INT, 
@COD_ESTA_LOG INT OUT  

BEGIN
    SET @COD_ESTA_LOG = 5
END
  

Mens. 102, Level 15, State 1, Line 3       Incorrect syntax near 'OUT'.

    
asked by Carlos Fox 29.03.2017 в 16:34
source

1 answer

4

Unless you are creating a stored procedure the OUT clause is being used incorrectly since it is only supported for stored procedures the way you want to use it and in INSERT , UPDATE instructions, DELETE Y MERGE according to the official documentation: link

What you can do is create the stored procedure:

CREATE PROCEDURE MiProcedimiento
@COD_PERI INT, 
@COD_ESTA_LOG INT OUT  
AS
BEGIN

SET @COD_ESTA_LOG = 5

END

And send it to call if it is from SQL:

exec MiProcedimiento @COD_PERI, @COD_ESTA_LOG OUTPUT

Or from the programming language in which you are going to use the procedure.

    
answered by 29.03.2017 в 17:00