1 从#t2中插入#t1中没有的数据
select
ww, ww_index
into
#t1
from
calendar
where
ww_index between 1 and 3
order
by ww_index
select
ww, ww_index
into
#t2
from
calendar
where
ww_index between 1 and 6
order
by ww_index
insert
into #t1
select
* from #t2
where
not
exists (
select 1 from #t1 where #t2.ww_index = #t1.ww_index)
select
* from #t1
drop
table #t1
drop
table #t2
2,只向#t1插入#t1.#t2都有的
select
ww, ww_index
into
#t1
from
calendar
where
ww_index between 1 and 3
order
by ww_index
select
ww, ww_index
into
#t2
from
calendar
where
ww_index between 1 and 6
order
by ww_index
insert
into #t1
select
* from #t2
where
exists (
select 1 from #t1 where #t2.ww_index = #t1.ww_index)
select
* from #t1
drop
table #t1
drop
table #t2
3,如果#t1和#t2有并集,则把#t2的数据全部插入#t1
select
ww, ww_index
into
#t1
from
calendar
where
ww_index between 1 and 3
order
by ww_index
select
ww, ww_index
into
#t2
from
calendar
where
ww_index between 1 and 6
order
by ww_index
insert
into #t1
select
* from #t2
where
exists (
select 1 from #t1,#t2 where #t2.ww_index = #t1.ww_index)
select
* from #t1
drop
table #t1
drop
table #t2
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23155850/viewspace-631542/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23155850/viewspace-631542/