Solved

Copying a Row?

Posted on 2008-10-31
5
151 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
  • 3
  • 2
5 Comments
 
LVL 142

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 142

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 142

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

19 Experts available now in Live!

Get 1:1 Help Now