这个不是一个语句执行就可以的。页面上输入单位编号 点查询执行 select * from table where 单位='输入的单位'然后输入新单位编号,例如 新单位执行 insert into table select '新单位',col1,col2 from table where 单位='输入的单位'declare @table table (id int,col varchar(1),col1 varchar(6)) insert into @table select 1,'a','a1' union all select 2,'b','a2' union all select 3,'c','a3'select * from @table where col='a' /* id col col1 ----------- ---- ------ 1 a a1 */--把a变成g再插入: insert into @table select id,'g',col1 from @table where col='a'select * from @table /* id col col1 ----------- ---- ------ 1 a a1 2 b a2 3 c a3 1 g a1 */
select '新的单位编码' ,其他列 from tb where 单位='爱仕达'
CREATE table tb(id int,note varchar(100))
go
insert into tb(id,note) values(1,'aaa')
insert into tb(id,note) values(1,'bbb')
insert into tb(id,note) values(2,'ccc')
select * from tb--查看结果1
insert into tb select 2,note from tb where id = 1
select * from tb--查看结果2
drop table tb结果1:
id note
----------- ------------
1 aaa
1 bbb
2 ccc
结果2:
id note
----------- ------------
1 aaa
1 bbb
2 ccc
2 aaa
2 bbb
是你想要的结果吗?
如果有多表,表之间如何关联?
发帖注意事项
http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
insert into table
select '新单位',col1,col2 from table where 单位='输入的单位'declare @table table (id int,col varchar(1),col1 varchar(6))
insert into @table
select 1,'a','a1' union all
select 2,'b','a2' union all
select 3,'c','a3'select * from @table where col='a'
/*
id col col1
----------- ---- ------
1 a a1
*/--把a变成g再插入:
insert into @table
select id,'g',col1 from @table where col='a'select * from @table
/*
id col col1
----------- ---- ------
1 a a1
2 b a2
3 c a3
1 g a1
*/