Solved

What is wrong with my sql statement? (MSSQL)

Posted on 2014-01-16
5
522 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach 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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

773 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