--楼主根据主键选择. select b.bm,b.rksl+isnull(a.rksl,0) as rksl,b.cksl+isnull(a.cksl,0) as cksl,b.sj from table2 b left join table1 a on b.bm=a.bm and b.sj=a.sj
表一有A是8月的,表二也有A是9月的, 但是这两个记录是不同的,但是怎么A的八月的纪录不要了拉??
这个意思吗? select B.BM, case when (B.RKSL=0 and B.CKSL=0) then A.RKSL else B.RKS end as RKSL, case when (B.RKSL=0 and B.CKSL=0) then A.CKSL else B.CKSL end as CKSL, case when (B.RKSL=0 and B.CKSL=0) then A.sj else B.sj end as sj from A,B where B.Bm*=A.Bm
select b.bm,b.rksl+isnull(a.rksl,0) as rksl,b.cksl+isnull(a.cksl,0) as cksl,b.sj
from table2 b left join table1 a on b.bm=a.bm and b.sj=a.sj
但是这两个记录是不同的,但是怎么A的八月的纪录不要了拉??
select B.BM,
case when (B.RKSL=0 and B.CKSL=0) then A.RKSL else B.RKS end as RKSL,
case when (B.RKSL=0 and B.CKSL=0) then A.CKSL else B.CKSL end as CKSL,
case when (B.RKSL=0 and B.CKSL=0) then A.sj else B.sj end as sj
from A,B
where B.Bm*=A.Bm