0

在这里我需要得到消息。如果我在应用程序中输入电子邮件 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
4

2 回答 2

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;
于 2013-02-06T06:53:07.593 回答
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
于 2013-02-06T06:53:36.587 回答