如果主库a里有有个表fx_outlist其主键是identify,外键是outno
现在有个同样属性的目标库b有个表为fx_outlist_2011
假设现在fx_outlist里有10个identify对应着相同的outno
fx_outlist里有主库中的4条同样数据
请问怎么把剩下的6条插入目标库中
insert into FxStorehouse.dbo.Fx_OutList_2011
SELECT * from Fx_OutList where Fx_OutList.Out_No = @Out_No--(@Out_No就是所说的相同单号)
我这么写肯定不对
现在有个同样属性的目标库b有个表为fx_outlist_2011
假设现在fx_outlist里有10个identify对应着相同的outno
fx_outlist里有主库中的4条同样数据
请问怎么把剩下的6条插入目标库中
insert into FxStorehouse.dbo.Fx_OutList_2011
SELECT * from Fx_OutList where Fx_OutList.Out_No = @Out_No--(@Out_No就是所说的相同单号)
我这么写肯定不对
SELECT a.*
from Fx_OutList as a
left join FxStorehouse.dbo.Fx_OutList_2011 as b on a.Out_No=b.Out_No
where b.Out_No is null
where not exists(select 1 from b..fx_outlist_2011 m where n.outno = m.outno and n.outno = @out_no)
insert into b..fx_outlist_2011 select * from a..fx_outlist n
where not exists(select 1 from b..fx_outlist_2011 m where n.outno = m.outno)--如果你需要指定outno,则如下:
insert into b..fx_outlist_2011 select * from a..fx_outlist n
where not exists(select 1 from b..fx_outlist_2011 m where n.outno = m.outno and n.outno = @outno) --其中@outno是个变量,其值自己输入。