Stored procedures are special objects available in sql server. Its a precompiled statements where all the preliminary parsing operations are performed and the statements are ready for execution.
Its very fast when compared to ordinary sql statements where the sql statements will undergone a sequence of steps to fetch the data
Stored procedure involves various syntax based on the parameters passed. Let me show you a generic syntax for a stored procedure.
Create procedure procName as begin ----Your query should be return here end
CREATE PROCEDURE SPWITHPARAMETER_AND_RETURN_VALUE ( @EMPID INT, @IDVAL INT, @RETURNVALUE INT =0 OUT ) AS DECLARE @COUNT INT BEGIN SELECT @COUNT=COUNT(*) FROM JOINTABLE WHERE EMPID=@EMPID AND IDVAL=@IDVAL IF(@COUNT >0) BEGIN SET @RETURNVALUE = 1; PRINT @RETURNVALUE RETURN @RETURNVALUE END ELSE BEGIN SET @RETURNVALUE = 1; PRINT @RETURNVALUE RETURN @RETURNVALUE END END
EXEC SPWITHPARAMETER_AND_RETURN_VALUE 2,3
shabbir like this