复制1列的表更改值,并将其插入同一个表中 [英] copy a table change values of 1 column and insert it in the same table

查看:209
本文介绍了复制1列的表更改值,并将其插入同一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



一些更多的信息,我得到一个表有4列。我需要一个精确的副本,但只需要更改一列的值。



假设该列名为客户编号,即123456(其他值不重要)。



我可以复制整个表,并将客户编号更改为123457并将该副本插入同一个表。



如果一切顺利,我应该有两倍



我使用的是MSSQL2008 R2

解决方案

尝试此操作

  INSERT CustomerTable ,Field3,Field4)
SELECT 123457,Field2,Field3,Field4
来自CustomerTable
WHERE customer = 123456


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 dont 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 1 customer in the database) records as i had before where only the customer number has changed.

I'm using MSSQL2008 R2

解决方案

Try this

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

这篇关于复制1列的表更改值,并将其插入同一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆