user3659480
user3659480

Reputation: 3

Writing Stored Procedures in Visual Studio 2010

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

Answers (2)

Thorsten Dittmar
Thorsten Dittmar

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

Anthony Horne
Anthony Horne

Reputation: 2522

It must be:

Set @ReturnCode=1

It is a variable declared further up.

Upvotes: 0

Related Questions