Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now