IF / ELSE depending on result of stored procedure
You should not use a stored procedure for this and use a function instead to check if the Admin Exists.
Then in your new stored procedure call the CheckAdminExists function:
CREATE FUNCTION [dbo].[CheckAdminExists] (@SID NVARCHAR(50), @AdminName NVARCHAR(MAX))RETURNS BITAS BEGINDECLARE @RetVal INTSELECT @RetVal = COUNT(Administrator.ID)FROM AdministratorWHERE Administrator.SID = @SID AND Administrator.Name = @AdminNameIF @RetVal > 0 BEGIN RETURN 1END RETURN 0ENDThen in your stored procedure call the function:DECLARE @AdminExists BITSELECT @AdminExists = [dbo].[CheckAdminExists]IF @AdminExists BEGIN -- your code ENDELSEBEGIN -- your codeEND
Indeed, use FUNCTION
.
But if you need to return more than 1, use OUTPUT
parameters.