Solved

How do I insert multiple rows into a single table with one INSERT statement?

Posted on 2006-10-31
3
616 Views
Last Modified: 2008-01-09
Really dumb question, but I'm totally confused.   I want to insert multiple rows into a table with one statement.  The obvious approach (well, at least I thought it was) is to execute the command...

INSERT INTO [MyDatabase].[dbo].[MenuActions] ([Menu_ID],[Name],[Sequence],[Action_Type],[Action],[Target],[IsDefault],[Target_Group])
VALUES
   ('ec404cee-6cfc-4279-a396-c7cb271f1309', 'Submit',100, 'JavaScript', 'submit()','_blank',1,'viewers'),
   ('ec404cee-6cfc-4279-a396-c7cb271f1309', 'Cancel',200, 'JavaScript', 'cancel()','_blank',1,'viewers'),
   ('ec404cee-6cfc-4279-a396-c7cb271f1309', 'Help',300, 'JavaScript', 'help()','_blank',1,'viewers')
GO

Well, SQL Server chokes on the ',' after the first entry.  

Is it possible to do this? If so, how does it need to be formatted?
0
Comment
Question by:sasdevelopment
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 125 total points
ID: 17843858
INSERT INTO [MyDatabase].[dbo].[MenuActions] ([Menu_ID],[Name],[Sequence],[Action_Type],[Action],[Target],[IsDefault],[Target_Group])
SELECT 'ec404cee-6cfc-4279-a396-c7cb271f1309', 'Submit',100, 'JavaScript', 'submit()','_blank',1,'viewers'
UNION ALL
SELECT'ec404cee-6cfc-4279-a396-c7cb271f1309', 'Cancel',200, 'JavaScript', 'cancel()','_blank',1,'viewers'
UNION ALL
SELECT 'ec404cee-6cfc-4279-a396-c7cb271f1309', 'Help',300, 'JavaScript', 'help()','_blank',1,'viewers'
GO
0
 
LVL 10

Expert Comment

by:AaronAbend
ID: 17846378
if you notice, nobody else has commented because aneesh has supplied the right answer... please award the points to him so other experts do not spend time reviewing. thanks!
0
 

Author Comment

by:sasdevelopment
ID: 17849442
Thanks Aneesh and Aaron.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

756 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