Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

multiple inserts in one query or procedure

Posted on 2011-09-29
11
Medium Priority
?
316 Views
Last Modified: 2012-05-12
is there a way to do a multiple insert to a table in sql
0
Comment
Question by:singsunn
[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
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 34

Accepted Solution

by:
Paul MacDonald earned 1500 total points
ID: 36816936
In the same row?  Yes  
In multiple rows with a common criteria?  Yes.

http://msdn.microsoft.com/en-us/library/aa933206(v=sql.80).aspx
0
 

Author Comment

by:singsunn
ID: 36816943
into multiple rows with one common criteria.
0
 
LVL 8

Expert Comment

by:Crashman
ID: 36816944
USE YourDB
GO
INSERT INTO MyTable (FirstCol, SecondCol)
SELECT 'First' ,1
UNION ALL
SELECT 'Second' ,2
UNION ALL
SELECT 'Third' ,3
UNION ALL
SELECT 'Fourth' ,4
UNION ALL
SELECT 'Fifth' ,5
GO

Open in new window

0
Industry Leaders: 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!

 
LVL 8

Expert Comment

by:Crashman
ID: 36816985
or
 INSERT INTO [t]
        (
          [camp1],
          [camp2],
          [camp3]
        )
 VALUES ( 1, 2, 3 ),
        ( 3, 4, 5 ),
        ( 6, 7, 8 ),
        ( 9, 10, 11 ),
        ( 12, 13, 14 )

Open in new window

0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36816999
Does...
     INSERT INTO TableName (Column1, Column2) VALUES (Value1, Value2) WHERE Criteria=Value
...not work?
0
 

Author Comment

by:singsunn
ID: 36817019
values to be inserted are read from an xml file, so i don't know how many set of values there going to be.
do i need dynamic sql query or is it possible to do this in stored procedure?
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36817029
I think you'd have to build the query dynamically.  You might be able to do this with a stored proc, but I'm not sure.
0
 
LVL 8

Expert Comment

by:Crashman
ID: 36817067
read this

http://blog.sqlauthority.com/2009/02/13/sql-server-simple-example-of-reading-xml-file-using-t-sql/

and use the
INSERT INTO TableX
select  field1,field2
FROM OPENXML ('Your parameters' )

Open in new window

0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 36817076
Nice.  Didn't know about that...
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36895234
>>values to be inserted are read from an xml file, so i don't know how many set of values there going to be. <<
Instead of hypotheicals, why don't you post the schema (CREATE TABLE) to your table, a sample Xml file and how they are mapped (if it is not obvious) and we can give you a complete example using either OPENXML() if you are still using SQL Server 2000 compatibility or the newer Xml Data Type Methods if you are using SQL Server 2005 or greater.
0
 

Author Closing Comment

by:singsunn
ID: 36990748
none
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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

604 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