Reputation: 3
I am trying to write a stored procedure which inserts the username and password into the database. And there is an Identity
column which auto-increments itself. But I am not able to get the syntax correct !
Here is the code snippet:
CREATE PROCEDURE dbo.SPRegisterUser
@Username_V nvarchar(100),
@Email_V nvarchar(100),
@Password_V nvarchar(100)
AS
BEGIN
Declare @count int;
Declare @ReturnCode int;
Select @count = COUNT(Username)
from Register
where Username = @Username_V
If @count > 0
Begin
Set ReturnCode = -1
End
Else
Begin
Set ReturnCode = 1
Insert into Register
values(@Username_V, @Email_V, @Password_V)
END
RETURN
The error generated is
Incorrect Syntax near'='
Incorrect syntax near RETURN
Upvotes: 0
Views: 70
Reputation: 56747
First of all, the following line
RETURN
needs to be replaced by this
RETURN @ReturnCode
Also you're missing the final END
Also, variables need to start with a @
, so change the two lines
SET ReturnCode ...
to
SET @ReturnCode ...
Upvotes: 2
Reputation: 2522
It must be:
Set @ReturnCode=1
It is a variable declared further up.
Upvotes: 0