日期:2014-05-18  浏览次数:20522 次

一个数据库表向另一个数据库表插入数据
Java code


A表

pscode    effectdate    terminationdate  
1        
2 
3         

B表
pscode    effectdate    terminationdate  
1         2011-01-01     2012-01-12
2         2009-10-22     2012-06-10
3         2007-02-02     2011-11-05
4         2010-02-03     2010-10-11
5         2009-09-09     2012-01-05


请问我怎么把B表里的effectdate字段和terminationdate字段插入到A表中,不等于A表中pscode的不插入进来




------解决方案--------------------
SQL code

update A
    set  effectdate=B.effectdate 
        ,terminationdate=B.terminationdate 
    from B where A.pscode=B.pscode

------解决方案--------------------
SQL code
update a set a.effectdate=b.effectdate,a.terminationdate=b.terminationdate
from b
where a.pscode=b.pscode