Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-10-31
3
Medium Priority
?
620 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
[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
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 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

Independent Software Vendors: 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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

718 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