在sql server 2008中执行存储过程时出错

在sql server 2008中执行存储过程时出错

问题描述:

create procedure spinsert
    @username nvarchar(100),
    @password nvarchar(100),
    @email nvarchar(100)
as
Begin
    Declare @count int
    Declare @returncode int
    Select @count=count(username) from register where username=@username
    if @count>0
      Begin
        Set @returncode=-1
      End
    Else
      Begin
        Set @returncode=1
        Insert into register values(@username,@password,@email)
      End
    Return @returncode as returnvalue
End



我得到这个错误或:


I get this error:

Msg 156, Level 15, State 1, Procedure spinsert, Line 19
Incorrect syntax near the keyword 'as'.

如果我没弄错,第19行是
If I am not mistaken line 19 is
Return @returncode as returnvalue



如果您正在尝试使用返回代码从存储过程返回数据只需从行中删除 as returnvalue ,它应该工作。



所以使用


If you are trying to return data from the stored procedure using a Return Code just remove the "as returnvalue" from the line and it should work.

So use

Return @returncode



参见使用返回码返回数据 [ ^ ]以获取描述。