Copy a table change values of 1 column and insert

2019-03-27 20:54发布

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.

1条回答
冷血范
2楼-- · 2019-03-27 21:44

Try this

INSERT CustomerTable(customer, Field2, Field3, Field4)
SELECT 123457, Field2, Field3, Field4
from CustomerTable
WHERE customer = 123456
查看更多
登录 后发表回答