Solved

What is wrong with my sql statement? (MSSQL)

Posted on 2014-01-16
5
528 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

688 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