0

I have this procedure, it asking me 2 input parameters, don't know why as I'm declaring the 2nd parameter (@monto) as an output:

ALTER PROCEDURE [dbo].[SP_MONTO_APROBADO]  
   @ID INT,  
   @MONTO INT OUTPUT  
AS  
BEGIN  
   SELECT @MONTO = MONTO_APROBADO   
   FROM LICITACION 
   WHERE COD_PROYECTO = @ID  
END 

enter image description here

Any hint please?

3
  • Because you need to tell whatever it is your using where to store the value. (not sure where that dialogue is from). Commented Mar 9, 2018 at 14:57
  • @Larnu please, could you tell me how, I'm very new to sqlserver (just 1 hour...) Commented Mar 9, 2018 at 14:59
  • 1
    Side note: you should not use the sp_ prefix for your stored procedures. Microsoft has reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future. It's also bad for your stored procedure performance. It's best to just simply avoid sp_ and use something else as a prefix - or no prefix at all! Commented Mar 9, 2018 at 15:49

3 Answers 3

1

Just because a parameter is marked as output, that doesn't mean that it cannot be supplied a value as input which will be readable within the stored procedure.

That is, T-SQL doesn't have a concept like inout because all output parameters are effectively this.

If you don't want to supply a value, make sure the parameter can accept nulls and then supply that as the input value.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. In that case, how could I declare it as null?
1

Because OUTPUT parameters are actually input-output parameters

Comments

0

When using a Stored procedure with an OUTPUT parameter, you still need to specify it when you execute the procedure.

I don't know what that image is from, however, using SQL you would need to do:

DECLARE @ID int, @Mondo int;
SET @ID = 1; --guessed value

EXEC SP_MONTO_APROBADO @ID, @Mondo OUTPUT;

PRINT @Mondo; --Don't know what you're doing with the OUTPUT value

Not specifying the second second parameter would result in a syntax error; as you aren't providing enough parameters for the SP. Regardless of if a Parameter in an input or output you still need to provide them at execution so that the Data engine knows where to get the values from, or where to store the resulting ones.

Also, it's work noting that prefixing your objects like that is a bad idea. Is the sp_ prefix still a no-no?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.