Solved

Copying a Row?

Posted on 2008-10-31
5
153 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

823 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