?
Solved

trying to insert output OrderID

Posted on 2013-05-27
2
Medium Priority
?
478 Views
Last Modified: 2013-05-27
I am trying to insert bot Orders and OrderDetails from one table into 2 tables but cannot remember how to use the Output. inserted in the second insert into statement.

Any ideas?

INSERT INTO WW.ClientOrders
                      (OrderDate, ClientOrderNumber, Client, ResellerName, PaymentOption)
SELECT     MIN(OrderDate) AS OrderDate, ClientOrderNumber, MIN(Client) AS Client, MIN(ResellerName) AS ResellerName, MIN(PaymentOption) AS PaymentOption
FROM         WW.ClientOrderImport
GROUP BY ClientOrderNumber
Output inserted.OrderID

INSERT INTO WW.ClientOrderDetails
           (DeliveryDateRequest, Product, GrowthStage, StandingOrder, Comments, 
		Quantity, ClientSpecialDiscount, ResellerSpecialDiscount,OrderID)
SELECT     i.DeliveryDateRequest, i.Product, i.GrowthStage, i.StandingOrder, i.Comments, 
i.Quantity, i.ClientSpecialDiscount, i.ResellerSpecialDiscount, 
                      inserted.OrderID
FROM         WW.ClientOrderImport AS i INNER JOIN
                      WW.ClientOrders AS o ON i.ClientOrderNumber = o.ClientOrderNumber

Open in new window

0
Comment
Question by:Shawn
[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
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 39199844
You need to insert them into a temp table


INSERT INTO WW.ClientOrders
                      (OrderDate, ClientOrderNumber, Client, ResellerName, PaymentOption)
Output inserted.OrderID into @TmpTable
SELECT     MIN(OrderDate) AS OrderDate, ClientOrderNumber, MIN(Client) AS Client, MIN(ResellerName) AS ResellerName, MIN(PaymentOption) AS PaymentOption
FROM         WW.ClientOrderImport
GROUP BY ClientOrderNumber

then you can use the values from this table
0
 
LVL 1

Author Closing Comment

by:Shawn
ID: 39199860
great, thank you!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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 shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

764 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