答案 0 :(得分:0)
您需要像这样的存储过程获取返回值-
DECLARE @returnvalue INT
EXEC @returnvalue = StudentExists Bob
然后您就可以满足If
条件了。
答案 1 :(得分:0)
首先,您的存储过程应返回值:
CREATE PROCEDURE SubjectExists @SubjName varchar(20)
AS
BEGIN
DECLARE @ReturnValue int
SELECT @ReturnValue = CASE WHEN EXISTS(
SELECT *
FROM Subject
WHERE Subject_Name = @SubjName
)
THEN CAST (1 AS BIT)
ELSE CAST (0 AS BIT)
END
RETURN @ReturnValue
END
然后,您可以声明一些表来存储存储过程的结果,如果符合条件,则运行代码
DECLARE @FooValue int;
EXEC @FooValue = SubjectExists 'helloWorld!:)'
IF @FooValue = 1
BEGIN
DELETE FROM Subject
WHERE Subject_Name = @SubjName;
END