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
Solved

Copying a Row?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server - Replace Carriage Returns for Excel Exports 17 57
sql server insert 12 40
SQL - format decimal in a string 5 39
query question 12 32
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.

856 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