Solved

Copying a Row?

Posted on 2008-10-31
5
157 Views
Last Modified: 2012-05-05
I have an Orders Table and I would like to copy an Order and assign it to another Order.

The only thing that would be required to changed would be the field CustomerID where I would change the customerID for that order.

The obvious approach would be to copy out all the fields from the order and insert it into the new row. But is there anyway automate this so it automatically does the insert and update for me?
0
Comment
Question by:directxBOB
[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
  • 3
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22850325
you mean, something like this:
INSERT INTO order_table ( CustomerID, OrderDate )
SELECT 2, getdate()
  FROM order_table
 WHERE CustomerID = 1
   AND OrderID = 123456

Open in new window

0
 

Author Comment

by:directxBOB
ID: 22850520
Can you explain how this works?

Mainly :

SELECT 2, getdate()
  FROM order_table
 WHERE CustomerID = 1
   AND OrderID = 123456
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22850661
actually, the example was not really "speaking"..
you will need to insert into and query more of the "order_Table" columns, but as I don't know your table/column names...

0
 

Author Comment

by:directxBOB
ID: 22850718
Yes I understood that part but I wasn't really sure about:

SELECT 2, getdate()

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22850844
2 would be the new customerid, and getdate() as "new" order date for the new rows..
0

Featured Post

Technology Partners: 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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 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