Search code examples
c#sql-serverdatabasevisual-studio-2015syntax-error

SQL46010 Syntax Error when creating a stored procedure in Visual Studio 15


First time question on here as there are usually answers already provided but I can't find an appropriate one for my issue.

I have created a database table in Visual Studio 15 and am trying to create a stored procedure to add data. However, I am getting the SQL46010 error and it is stating 'Incorrect syntax near User'. My code is below:

CREATE PROCEDURE [dbo].[BugAddOrEdit]
    @mode nvarchar(10),
    @BugID int,
    @User nvarchar(50),
    @Subject nvarchar(50),
    @Description nvarchar(MAX)
AS
    IF @mode = 'Add'
    BEGIN
        INSERT INTO Bugs(User, Subject, Description)
        VALUES (@User, @Subject, @Description)
    END

I just can't figure out how to get it to go away. Any help would be greatly appreciated.

Many thanks


Solution

  • User is a reserved keyword, so you'll have to surround it with square brackets: [User].

    CREATE PROCEDURE [dbo].[BugAddOrEdit]
        @mode nvarchar(10),
        @BugID int,
        @User nvarchar(50),
        @Subject nvarchar(50),
        @Description nvarchar(MAX)
    AS
        IF @mode = 'Add'
        BEGIN
            INSERT INTO Bugs([User], Subject, Description)
            VALUES (@User, @Subject, @Description)
    END