Solved

What is wrong with my sql statement? (MSSQL)

Posted on 2014-01-16
5
517 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:Kdo
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now