Solved

What is wrong with my sql statement? (MSSQL)

Posted on 2014-01-16
5
525 Views
Last Modified: 2014-01-16
Hi Experts,

My simple query (see code block below)

insert into entree_items (label) values
('Tekstvak met verduidelijking'),
('Soort aanvraag stage'),
('Soort aanvraag stage op basis van detachering'),
('Soort aanvraag Afstudeeronderzoek'),
('Eerder in dienst geweest?'),
('Indien: personeelsnummer')

go

Open in new window


keeps getting the same error

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ','.

When I only insert a single line the query is succesful

Help!
0
Comment
Question by:Steynsk
5 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39785411
What version of SQL? 2005 or 2008?
0
 
LVL 11

Accepted Solution

by:
Simone B earned 500 total points
ID: 39785419
You have both SQL 2005 and 2008 listed in your topics. But if you're using 2005, you have to do inserts for each line, as follows. Multiple comma separated inserts using INSERT INTO ... VALUES is supported in 2008 and above.

insert into entree_items (label) VALUES ('Tekstvak met verduidelijking')
insert into entree_items (label) VALUES ('Soort aanvraag stage')
insert into entree_items (label) VALUES ('Soort aanvraag stage op basis van detachering')
insert into entree_items (label) VALUES ('Soort aanvraag Afstudeeronderzoek')
insert into entree_items (label) VALUES ('Eerder in dienst geweest?')
insert into entree_items (label) VALUES ('Indien: personeelsnummer')

Open in new window

0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 39785449
Lots of good advise already.  2005 and 2008 are different.

If you want a single query that will work for both versions, use a subselect, not values.

INSERT INTO mytable (name)
SELECT 'name 1'
UNION ALL
SELECT 'name 2'
etc...


Kent
0
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 39785509
Thanks is was a 2005 server
0
 
LVL 11

Expert Comment

by:Simone B
ID: 39785513
Thanks for the points!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question