日期:2014-05-18 浏览次数:20787 次
--更新 update b set b.fraction = a.fraction from a join b on a.name = b.name --插入 insert into b select name,fraction from a t where not exists (select 1 from b where name = t.name)
------解决方案--------------------
加个存储过程的创建,把那段放进去就是了。
create proc get_UpdateAndInsert as begin --更新 update b set b.fraction = a.fraction from a join b on a.name = b.name --插入 insert into b select name,fraction from a t where not exists (select 1 from b where name = t.name) end
------解决方案--------------------
create table a(name varchar(10),fraction int,status bit)
create table b(name varchar(10),fraction int)
insert a
select '张三',80,0 union all
select '李四',70,0 union all
select '王五',58,1
insert b
select '张三',20 union all
select '王五',58
go
insert b(name,fraction) 
select a.name,a.fraction from a 
where not exists(select 1 from b where a.name=b.name)
/*(所影响的行数为 1 行)*/
go
select * from b
/*
name  fraction
----   -----
张三    20
王五    58
李四    70
*/
go
drop table a,b