插入满足特定条件的任何记录的副本



很抱歉这个有点幼稚的问题,但我对SQL相对较新。有人可以帮我编写SQL代码(SQL Server 2014(吗?

我有一个有 10 列的表格"A"。第 9 列具有以下四个值中的任何一个:"测试"、"保持"、"开始"或"标志">

我想插入第 9 列值 ="保留"或"Go"的任何记录的重复副本,并将其更改为值"步骤 3"。

感谢您的帮助!

你使用insert . . . select

insert into t (col1, . . . col10)
select col1, . . . col8, 'Step 3', col10
from t
where col9 in ('Hold', 'Go');

如果其中一列是自动生成的,则只需将其省略:

insert into t (col2, . . . col10)
select col2, . . . col8, 'Step 3', col10
from t
where col9 in ('Hold', 'Go');

最新更新