473,415 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,415 software developers and data experts.

why incorrect syntax near ',' when inserting multiple rows at a time in a table?

147 100+
Hi,

I am working on SQL 2008 database. In Micosoft SQL server Management studio, i am trying to insert multiple records at a time in a table, using this query

Expand|Select|Wrap|Line Numbers
  1.  insert into test1 values(6,'san6',1),( 7,'san7',1);
Error:
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ','.

I think so the syntax was correct. But i dont know why am facing this error. The same problem in SQL Server 2000 also.I am working on my server database.

Please help me out. Thanks in advance.
Oct 6 '10 #1
13 13711
ck9663
2,878 Expert 2GB
You can use a SELECT even with fixed value...Try something like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. insert into test1 
  3. select 6,'san6',1
  4. union all
  5. select 7,'san7',1
  6.  
  7.  
Happy Coding!!!

~~ CK
Oct 6 '10 #2
santhanalakshmi
147 100+
Hi,

The code is working finely, which you told to try me. This also very helpful for me. Thanks. Can you tell me ? why my code is not working ?
Oct 6 '10 #3
gpl
152 100+
Very simply, when inserting literal values, you may only insert 1 row at a time.

As the language allows you insert the result of a query, you can use a union query to generate a result set containing multiple rows of literals
Oct 6 '10 #4
almaz
168 Expert 100+
santhanalakshmi, your original script is absolutely correct for SQL Server 2008, but not for SQL Server 2000.

Inserting multiple rows using "insert...values" command is one of new features of SQL Server 2008
Oct 8 '10 #5
santhanalakshmi
147 100+
But my original script its not running..Facing the following errors:

Error:
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ','.
Oct 8 '10 #6
almaz
168 Expert 100+
Do you connect to SQL Server 2008?

To verify the version of SQL Server you are connected to run the following query:

Expand|Select|Wrap|Line Numbers
  1. print @@version
To verify that your database have a SQL2008 compatibility level, check whether the following script returns "100" or not.

Expand|Select|Wrap|Line Numbers
  1. select compatibility_level from sys.databases where database_id=db_id()
Oct 8 '10 #7
santhanalakshmi
147 100+
hi,
Thanks for your help ?

when i run this query ?

Expand|Select|Wrap|Line Numbers
  1. print @@version 
output :

Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)


and the second query

Expand|Select|Wrap|Line Numbers
  1. use master
  2. select cmptlevel from sysdatabases where dbid=db_id()
output :
80

In my system, i installed SQL 2000 plus SQL 2008 ? How can i change my version from SQL 2000 to SQL 2008 version.
Oct 8 '10 #8
almaz
168 Expert 100+
It means that you are connecting to SQL Server 2000, not SQL Server 2008.

SQL Server 2000 does not allow you to add multiple rows using "insert...values" command, so you should use approach suggested by ck9663
Oct 8 '10 #9
NeoPa
32,556 Expert Mod 16PB
Well caught Almaz. I thought that was available in 2008 (I knew it wasn't in 2005 because I tried it and it failed ;-( ), but I wasn't sure if an outer level of parentheses was required (INSERT Examples (Transact-SQL) tells me it isn't). The OP stated it was SQL 2008 right from the start, which threw me.
Oct 8 '10 #10
santhanalakshmi
147 100+
Dear sir,

You explained me a lot. Thanks for your response. Did you having own blogs ? In future, i need of your help. How can i contact you ? thanks
Oct 8 '10 #11
NeoPa
32,556 Expert Mod 16PB
SanthanaLakshmi:
In future, i need of your help. How can i contact you ?
I'm not sure who this is addressed to, but the only way you can request help on here is to post questions in the forums.

Any member is welcome to invite you to make alternative contact with them, but otherwise we have strict rules forbidding members contacting other members directly for technical help.
Oct 8 '10 #12
ALMAZ, This just helped me a great deal, thank you very much!!!
Aug 4 '16 #13
almaz
168 Expert 100+
My pleasure. It's great to know that even after six years these posts are helpful for someone :).
Aug 4 '16 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Joachim Klassen | last post by:
Hi all, first apologies if this question looks the same as another one I recently posted - its a different thing but for the same szenario:-). We are having performance problems when...
1
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." ...
1
by: mabubakarpk | last post by:
HI. I am using SQL Server 2000. I generate a script of some table from EmpDB database when I run script in query analyzer it return error "Incorrect syntax near 'COLLATE'." Scripts is ...
3
by: wallic | last post by:
Hello, This is my first post and I am a beginner with SQL code. The code below is supposed to update a new table (loctable) with a calculated value based on the original table (hra_data). ...
1
by: =?Utf-8?B?QmlsIENsaWNr?= | last post by:
I wrote a stored procedure that runs fine when I execute from SQL 2005 Management Studio, and runs ok when I step into it from VS2005. Both return a value of 0, drop, create & populate the table. ...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
0
by: MalingreM | last post by:
Hi, I'm quite new to sql2005, and I've the following problem. When I insert records in table Data one by one, the insert/update trigger fires correctly, but: when i insert multiple records at once;...
1
by: karenkksh | last post by:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. ...
3
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a...
5
NeoPa
by: NeoPa | last post by:
As the title implies, I am getting the following error message with some SQL I'm trying to use. I'm using MS Management Studio 2008 with a link to a 2005 server. What confuses me is that when I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.