Copy a table change values of 1 column and insert it in the same table

。_饼干妹妹 提交于 2019-12-04 22:33:51

问题


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:


Try this

INSERT CustomerTable(customer, Field2, Field3, Field4)
SELECT 123457, Field2, Field3, Field4
from CustomerTable
WHERE customer = 123456


来源:https://stackoverflow.com/questions/8724318/copy-a-table-change-values-of-1-column-and-insert-it-in-the-same-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!