--数据从一张表转到另一张表,表结构需相同
--先是把查询到的结果插入到另一张表,然后通过关联主键去删除源表的数据,从而达到转移数据的目的
--将查询的数据插入表的写法,以及表关联删除也可参考本例
insert into tb_lot_consume_his select top 5000 a.* from tb_lot_consume a with(nolock) 
left join plan_wo b with(nolock) on a.wo_code = b.wo_code 
where a.create_by = 'tn_busi_jexe_work_in_out' and isnull(a.out_lot_no,'')<>'' 
and b.wo_state = 9;
delete from tb_lot_consume from tb_lot_consume a
inner join tb_lot_consume_his b on a.lot_consume_id = b.lot_consume_id;


--表关联修改的例子
update bs_eqpt_all set is_real = 0 from bs_eqpt_all a with(nolock) 
left join bs_eqpt_type b with(nolock) on a.eqpt_type_id = b.eqpt_type_id 
where b.eqpt_type_name = '虚拟' and a.is_real = 1
Copyright © TouchNet 2015 all right reserved,powered by Gitbook最后修订时间: 2022-06-21 09:21:02

results matching ""

    No results matching ""