添加ELSE
块:
IF not EXISTS(SELECT * FROM Resource WHERE Email= @Email)
BEGIN
if(@status = 'Insert')
BEGIN
Insert into resource(FirstName, LastName, Password,
Role, Email, Phone, OrganisationID)
values (@FirstName,@LastName,@Password,
@Role,@Email,@Phone,@OrganisationID)
end
END
ELSE
BEGIN
RETURN 0;
END;
或者:您可以将条件移动到IF
这样的:
IF not EXISTS(SELECT * FROM Resource WHERE Email= @Email)
AND @status = 'Insert'
BEGIN
Insert into resource(FirstName, LastName, Password,
Role, Email, Phone, OrganisationID)
values (@FirstName,@LastName,@Password,
@Role,@Email,@Phone,@OrganisationID);
END
ELSE
BEGIN
RETURN 0; -- It depends on the return type
END;