The following Stored Procedure is used which returns an Integer value 1 if the StudentId exists and 0 if the StudentId does not exists.
Create Procedure CheckStudentId(@StudentId int)
As
Begin
Declare @Exist int
IF Exist( Select StudentId From Student Where StudentId=@StudentId)
Begin
Set @Exist = 1
End
Else
Begin
Set @Exist=0
end
Return @Exist
end
Execute The Store Procedure:
In order to fetch the returned integer value from the Stored Procedure, you need to make use of an Integer variable and use along with the EXEC command while executing the Stored Procedure.
In order to fetch the returned integer value from the Stored Procedure, you need to make use of an Integer variable and use along with the EXEC command while executing the Stored Procedure.
Syntax:
Declare @ReturnValue Int
Exec @ReturnValue=<Store Procedure Name> <Parameters>
Select @ReturnValue
Example:
Declare @ReturnValue
Exec @ReturnValue = CheckStudentId 1
Select @ReturnValue