Here is my sample:
ALTER PROCEDURE EmpFirstName
@myParam int,
@empFName varchar(20) output
AS
BEGIN
SET NOCOUNT ON;
SELECT @empFName = empfname
FROM FE_QEMP
WHERE empno = @myParam
END
GO
myParam is the input and empFName will carry the output, so the procedure
should only take 1 parameter since empFName is the output, but in my case
i get this error:
Msg 201, Level 16, State 4, Procedure
EmpFirstName, Line 0 Procedure or
function ‘EmpFirstName’ expects
parameter ‘@empFName’, which was not
supplied.
This is the way i called the procedure:
DECLARE @returnValue varchar(20)
EXEC @returnValue = EmpFirstName 10
SELECT 'Return Value ' = @returnValue
Return values and output parameters are two different things. If you want to call it with an output parameter, you’d do it like this:
If you want to call it in the manner that you described in your example, then you need to alter the stored procedure to state
RETURNS VARCHAR(20)and remove theoutputparameter. To return a value, you have to explicitly callreturn. In your example, you’ddeclarea variable, assign it in theselectstatement, then callreturn @varName.