Incorrect syntax next to ','

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

These codes work fine, but when I try to add multiple values, this results in an error

Error: Incorrect syntax next to ','.

 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 
+4
source share
2 answers

To use the multi-line syntax VALUES(),() , you need to start SQL Server 2008 (or newer).

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

+14
source

You can do it as follows:

 insert into [Temp].[dbo].[Student] select 'Aname', 'Alname', 'AMale' union all select 'Bname', 'BAlname', 'BMale' 

etc.

thanks

Pavel.

+6
source

All Articles