期待SELECT或'('在Sql中

时间:2012-10-12 18:21:51

标签: sql sql-server sql-server-2008

基本上当我注册时(注册详细信息转到登录表),此数据将转到2个表:

  1. 登录表
  2. 注册表(特定)
  3. 使用@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
    

    进一步澄清,我已经附上了下面的图片:

    enter image description here

2 个答案:

答案 0 :(得分:7)

之后您的ELSE遗失IF

ELSE (@Attrib = 'Financial Supporter') 

应该是

ELSE IF (@Attrib = 'Financial Supporter') 

答案 1 :(得分:6)

ELSE案例没有条件,因此会报告语法错误。

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

我认为您打算将其作为ELSE IF

ELSE
 IF (@Attrib = 'Financial Supporter')