The title basically sums it pretty much all up, with what I'm trying to accomplish here.
Some more info, I got a table that has 4 columns. I need an exact copy of it but only need to change the values of one column.
Suppose that column is named customer number which is 123456 (the other values don't really matter).
How can I copy the entire table and change the customer number to 123457 and insert that copy back into the same table.
If everything went right, I should have twice as much (there is only one customer in the database) records as I had before where only the customer number has changed.
I'm using MSSQL2008 R2.
Move or copy just the contents of a cell You can also edit and select cell data in the formula bar. Select the row or column that you want to move or copy. In the cell, click where you want to paste the characters, or double-click another cell to move or copy the data. or press Ctrl+V.
The SQL INSERT INTO SELECT Statement The INSERT INTO SELECT statement copies data from one table and inserts it into another table. The INSERT INTO SELECT statement requires that the data types in source and target tables match. Note: The existing records in the target table are unaffected.
INSERT INTO Syntax It is possible to write the INSERT INTO statement in two ways: 1. Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)
UPDATE table SET col = new_value WHERE col = old_value AND other_col = some_other_value; UPDATE table SET col = new_value WHERE col = old_value OR other_col = some_other_value; As you can see, you can expand the WHERE clause as much as you'd like in order to filter down the rows for updating to what you need.
Try this
INSERT CustomerTable(customer, Field2, Field3, Field4)
SELECT 123457, Field2, Field3, Field4
from CustomerTable
WHERE customer = 123456
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With