?
Solved

Correct syntax to add multiple rows to a table.....?

Posted on 2008-11-10
5
Medium Priority
?
204 Views
Last Modified: 2013-11-05
What is the correct syntax to use for this INSERT..???

I'm getting this error:

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'values'.



insert into dbo.media_expense  (media_date, media_cost)
values ( '2008-10-20',3819.00)
values ('2008-10-21',3832.00)
values  ('2008-10-22',3809.00)
values  ('2008-10-23',3784.00)
values  ('2008-10-24',4214.00)
values  ('2008-10-25',0.00)
values  ('2008-10-26',0.00)
values  ('2008-10-27',4191.00)
values  ('2008-10-28',3954.00)
values  ('2008-10-29',4034.00)
values  ('2008-10-30',3808.00)
values  ('2008-10-31',4129.00)
values  ('2008-11-01',0.00)
values  ('2008-11-02',0.00)
values  ('2008-11-03',3639.00)
values  ('2008-11-04',4969.00)
values  ('2008-11-05',5074.00)
values  ('2008-11-06',5129.00)
values  ('2008-11-07',5504.00)
values  ('2008-11-08',0.00)
values  ('2008-11-09',0.00)
0
Comment
Question by:MIKE
  • 4
5 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22927240
You will have to do multiple INSERT statements or use UNION ALL syntax.
0
 
LVL 17

Author Comment

by:MIKE
ID: 22927246
HOW please..???
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22927248
Like this with UNION...
insert into dbo.media_expense (media_date, media_cost)
select  '2008-10-20',3819.00
union all select '2008-10-21',3832.00
union all select '2008-10-22',3809.00
...

Open in new window

0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22927253
Like this with multiple statements...
insert into dbo.media_expense (media_date, media_cost)
values ('2008-10-23',3784.00)
insert into dbo.media_expense (media_date, media_cost)
values ('2008-10-24',4214.00)
insert into dbo.media_expense (media_date, media_cost)
values ('2008-10-25',0.00)
...

Open in new window

0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22927264
I don't have my SQL Studio handy, but if you have the above in SQL Management Studio, just do a find and replace on "values (" and replace with "UNION ALL SELECT ", then replace ")" with "".  Do this replacement on selection outside of INSERT INTO... line.

This will quickly allow you to change what you have to single statement.  You will just have to remove the UNION ALL from first select so it looks like my sample.

Hope that helps.

Kevin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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.
Suggested Courses

839 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