在这里我需要得到消息。如果我在应用程序中输入电子邮件ID,我应该收到电子邮件已经存在的消息?
IF not EXISTS(SELECT * FROM Resource WHERE Email= @Email)
if(@status = 'Insert')
BEGIN
Insert into resource(FirstName,LastName,Password,Role,Email,Phone,OrganisationID)
values (@FirstName,@LastName,@Password,@Role,@Email,@Phone,@OrganisationID)
END
答案 0 :(得分:0)
添加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;
答案 1 :(得分:0)
if not Exists (select Email from Resource where Email= @Email)
begin
set @status='Insert'
Insert into resource(FirstName,LastName,Password,Role,Email,Phone,OrganisationID)
values (@FirstName,@LastName,@Password,@Role,@Email,@Phone,@OrganisationID)
end
else begin set @status='EmailExists='+@Email end