exec('delete from c; insert into c select a,b,c,d from b union all select a,b,c,1 from a' )
exec('delete from c; insert into c select a,b,c,d from b union all select a,b,c,1 from a' )
CREATE PROC P AS BEGIN delete from c insert into c select a,b,c,d from b union all select a,b,c,1 from a END
现学现卖-- SQL Server 2008 statement merge c as t using (select a,b,c,d from b union all select a,b,c,1 from a) as s(a,b,c,d) on (t.a=s.a and t.b=s.b and t.c=s.c and t.d=s.d) when not matched by source then delete when not matched then insert (a,b,c,d) values(s.a,s.b,s.c,s.d);
insert into c
select a,b,c,d from b
union all
select a,b,c,1 from a'
)
insert into c
select a,b,c,d from b
union all
select a,b,c,1 from a'
)
AS
BEGIN
delete from c
insert into c
select a,b,c,d from b
union all
select a,b,c,1 from a
END
merge c as t
using (select a,b,c,d from b union all select a,b,c,1 from a) as s(a,b,c,d)
on (t.a=s.a and t.b=s.b and t.c=s.c and t.d=s.d)
when not matched by source then delete
when not matched then insert (a,b,c,d) values(s.a,s.b,s.c,s.d);
http://school.itzcn.com/index.html#
上面讲解的比较详细,希望对楼主有所帮助。
insert into c
select a,b,c,d from b
union all
select a,b,c,1 from a'
)
insert into c
select a,b,c,d from b
union all
select a,b,c,1 from a'
)