[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

What is wrong with my sql statement? (MSSQL)

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
Steynsk
Asked:
Steynsk
1 Solution
 
Lee SavidgeCommented:
What version of SQL? 2005 or 2008?
0
 
Simone BCommented:
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
 
Kent OlsenData Warehouse Architect / DBACommented:
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
 
SteynskAuthor Commented:
Thanks is was a 2005 server
0
 
Simone BCommented:
Thanks for the points!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now