2012-10-12 51 views
0

基本上當我註冊(登記細節進行到登錄表),然後這個數據變爲2個表:期待SELECT或「(」在SQL

  1. 登錄表
  2. 登記表(特定)

使用@Attrib我檢查哪些數據需要去哪個表。但在這裏,我得到一個錯誤附近的第一else部分。

錯誤是:

附近有語法錯誤@Attrib'期待SELECT或, '('

下面是代碼:

ALTER procedure [dbo].[Registration_SP] 
(
    @Email varchar(50), 
    @Password varchar(50), 
    @Repassword varchar(50), 
    @Attrib varchar(50) 
) 
AS 

BEGIN 

    Insert into Login (Email,Password,Repassword,Attrib) 
    values(@Email,@Password,@Repassword,@Attrib) 

    IF (@Attrib = 'Student') 
    BEGIN 
     Insert into StudentReg 
      (StudentId,FirstName,LastName,Gender,Address1,Address2,Address3, 
      LandPhone,MobilePhone,Budget,IsFinancialSupport,CourseName, 
      IsJobSeeker,Country,Region,IsSupportActive,RegDate,ImagePath, 
      ShortCode) 
     Values(@Email,'','','','','','','','','','','','','','','','','','') 
    END 
    ELSE (@Attrib = 'Financial Supporter') 
    BEGIN 
     Insert into SupporterReg 
     (SupporterId,SupporterName,University,ContactNo,StudentLocation,RegDate, 
     ImagePath,ShortCode) 
     Values(@Email,'','','','','','','') 
    END 

進一步澄清,我已經atttached的圖片如下:

enter image description here

回答

6

ELSE缺少IF算賬:

ELSE (@Attrib = 'Financial Supporter') 

應該

ELSE IF (@Attrib = 'Financial Supporter') 
+0

看起來你可能會在清理完代碼後在你的'ALTER'語句的結尾處遺漏了一個最後的'END'。不知道這是不是偶然的遺漏,我想我會指出。 – LittleBobbyTables

6

ELSE案件沒有條件,因此會報告語法錯誤。

-- Should be no condition here, syntax error. 
ELSE (@Attrib = 'Financial Supporter') 

我假設你想要它是ELSE IF

ELSE 
IF (@Attrib = 'Financial Supporter')