Solved

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

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