Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect syntax near ',' [closed]

INSERT INTO [Temp].[dbo].[Student]
    ([Fname], [Lname], [Gender])
    VALUES 
    (N'Aname', N'Alname', N'Male')
    GO

This codes workes fine but when I try to add multiple values it gives me an error

Error: Incorrect syntax near ','.

USE TEMP
GO

INSERT INTO [Temp].[dbo].[Student]
([Fname], [Lname], [Gender])
VALUES 
(N'Aname', N'Alname', N'Male'),
(N'Bname', N'Blname', N'Male')
GO
like image 491
Ebeen Avatar asked Jul 02 '12 15:07

Ebeen


People also ask

What is incorrect syntax near?

This indicates there is an incorrect symbol in the criteria of the query.

What does Incorrect syntax mean?

Syntax errors are mistakes in the source code, such as spelling and punctuation errors, incorrect labels, and so on, which cause an error message to be generated by the compiler.

Is user a keyword in SQL?

User is a reserved keyword, so you must use square brackets to make it explicit that you mean the object named "User" it, i.e. use [User] instead of User .


1 Answers

In order to use the multi-row VALUES(),() syntax, you need to be running SQL Server 2008 (or newer).

Since you are running SQL Server 2005, you need to run separate insert statements, use UNION/UNION ALL, or upgrade the instance (which is separate from Management Studio, which is just a client tool you use to connect to instances running any number of versions of SQL Server).

like image 87
Aaron Bertrand Avatar answered Sep 25 '22 18:09

Aaron Bertrand