I wrote a stored procedure which returns contract status for anauthor. If author doesn’t exist i’ll return -900. So, this is what i did
CREATE PROCEDURE AUthorContract
@user varchar(10)
AS
IF(@user NOT IN(select Au_id from Authors))
BEGIn
RETURN -900
END
ELSE
BEGIN
select contract from from Authors where Au_id = @user
END
GO
However, when I give a valid author id as input, it returns -900 and if i give some id it goes into else and just returns 0 . So, I reversed them and entered correct id, but it still just returns 0 and not the contract value.
Can u please help me out the mistake i have been doing. The DB is pubs.
stored procedure can “return” three types of things:
RETURNcommand@YourPartameter anydatatype OUTPUTSELECT * FROM YourTableyour procedure does not have a
RETURNcommand for normal exit, so it defaults to a value of zero. You need to check the result set in your application if the return value is zero.try this to RETURN the contact value:
try this to use an OUTPUT parameter:
Here is the result set, with an explicit return: