存储过程:
CREATE PROCEDURE validate
@blockID VARCHAR(255)
AS
BEGIN
IF @blockID = (SELECT blockID FROM block WHERE blockID = @blockID)
PRINT 'exists'
IF @blockID != (SELECT blockID FROM block WHERE blockID = @blockID)
PRINT 'does not exist'
END
输入错误的一个blockID时,如果条件不起作用则输入第二个。
答案 0 :(得分:2)
您可能想使用EXISTS
。
CREATE PROCEDURE validate
@blockID VARCHAR(255)
AS
BEGIN
IF EXISTS (SELECT blockID FROM block WHERE blockID = @blockID)
PRINT'exists'
ELSE
PRINT'not exists'
END