Solved

trying to insert output OrderID

Posted on 2013-05-27
2
474 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 500 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Throw Error 7 35
SQL Session Remains Open After ReportViewerControl Form is Closed. 8 36
Convert time stamp to date 2 57
Need to trim my database size 9 26
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…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

726 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