Solved

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

Posted on 2006-10-31
3
617 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tempdb Contention - SQL SERVER 10 41
Help with Data Warehouse / Data Marts 4 42
What is needed to become a DBA? 7 56
SQL Server View  - Timeout Expired 5 21
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

710 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