Reputation: 27
Anyone can help me to find the error in this code, when I execute it says
"Procedure or function 'dep_cnt' expects parameter '@cnt', which was not supplied."
I want to count number of departments in colombo.
CREATE PROCEDURE dep_cnt
@dep_loc varchar(10),
@cnt int
AS
SELECT @Cnt = count(*) FROM Department WHERE Dept_Loc = @dep_loc
And
EXEC dep_cnt @dep_loc = 'colombo'
Upvotes: 0
Views: 40
Reputation: 20509
You can either pass a @cnt
parameter with a value to your stored procedure call, or set a default of NULL
to the @cnt
parameter inside the procedure definition, like:
CREATE PROCEDURE dep_cnt
@dep_loc varchar(10)
, @cnt int = NULL
AS
SELECT @Cnt = count(*)
FROM Department
WHERE Dept_Loc = @dep_loc
EXEC dep_cnt @dep_loc = 'colombo'
Although I don't see much value in this, maybe you're looking for @cnt
as an output / returned value?
CREATE PROCEDURE dep_cnt
@dep_loc varchar(10)
, @cnt int OUTPUT
AS
SELECT @Cnt = count(*)
FROM Department
WHERE Dept_Loc = @dep_loc
DECLARE @cntResult int
EXEC dep_cnt @dep_loc = 'colombo', @cnt = @cntResult OUTPUT
You can find more info here about returning data from a stored procedure.
Upvotes: 1