Freelancer
Freelancer

Reputation: 9074

output parameter in stored procedure not working

I am new with stored procedures.

I have simple stored procedure for addition of two numbers as follows:

alter proc simpleProc 
(
    @Tax int ,
    @TotalAmount int,
    @sum int output     
)
as
BEGIN
set @sum=(@Tax+@TotalAmount)
print @sum
END

As we can see in this @sum is output parameter.

But when I execute it as follows:

exec simpleProc 908,82 

It gives me the following error:

Msg 201, Level 16, State 4, Procedure simpleProc, Line 0
Procedure or Function 'simpleProc' expects parameter '@sum', which was not supplied.

I have mentioned @sum as output parameter, but then also its demanding me to input @sum parameter.

What can be the mistake?

Upvotes: 2

Views: 3774

Answers (2)

Rohan
Rohan

Reputation: 3078

Yes it you haven't provided output parameter. Try this

    Declare @op int
    exec simpleProc 908,82,@op output
    //use op variable

Upvotes: 3

juergen d
juergen d

Reputation: 204904

You should give the procedure a variable where the output can be stored

declare @sum int
exec simpleProc 908, 82, @sum output

Upvotes: 2

Related Questions