Solved

SQL to copy a record and insert it using a specified new primary key

Posted on 2011-02-16
2
335 Views
Last Modified: 2012-06-22
I have an 80 coluimn table with lots of records and the Primary key is a column named OrderNum (and is NOT an identity field). I need to insert a new record with all identitical values as an existing record based on the OrderNum, except obviously the OrderNum can't be the same, so I need to assign the newly inserted OrderNum.

What would be the best SQL statement to accomplish this?
Let's say the record I need to copy is OrderNum=100500
and I need to assign the new record Ordernum=101880
0
Comment
Question by:bobPUNKbob
2 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 500 total points
ID: 34911368
try a syntax like this

INSERT INTO yourTable (OrderNum, col1, col2,....)
SELECT 101880, col1, col2,....
FROM yourTable
WHERE OrderNum = 100500
0
 

Author Closing Comment

by:bobPUNKbob
ID: 34912168
Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Sever Import/export problem 7 44
Rebooting Witness SQL Server 2 23
SQL Syntax 6 27
T-SQL: Need Group By to use "fuzzy logic"?? 3 11
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

735 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