select isnull(a.wpbh, b.wpbh),isnull(a.yuan,0),isnull(a.syue,0),isnull(a.wpbh, b.wpbh),isnull(b.yuan,0)
from tab1 aa
full join tab2 b on a.wpbh = b.wpbh and a.yuan = b.yuan
from tab1 aa
full join tab2 b on a.wpbh = b.wpbh and a.yuan = b.yuan
IsNull(A.wpbh, B.wpbh) As wpbh1,
IsNull(A.yuan, 0) As yuan1,
IsNull(A.syue, 0) As syue,
IsNull(A.wpbh, B.wpbh) As wpbh2,
IsNull(B.yuan, 0) As yuan2
From
tab1 A
Full Join
tab2 B
On A.wpbh = B.wpbh
select isnull(a.wpbh, b.wpbh),isnull(a.yuan,0),isnull(a.syue,0),isnull(a.wpbh, b.wpbh),isnull(b.yuan,0)
from tab1 aa
full join tab2 b on a.wpbh = b.wpbh and a.yuan = b.yuan
-----------
關聯條件寫的有問題。應該去掉 and a.yuan = b.yuan
create table tab1(wpbh varchar(10),yuan int,syue int)
insert tab1(wpbh,yuan,syue)
select '01','200','1' union all
select '02','300','3' union all
select '03','500','5'
go
create table tab2(wpbh varchar(10),yuan int)
insert tab2(wpbh,yuan)
select '01','300' union all
select '04','300'
go
--执行测试语句
select isnull(a.wpbh, b.wpbh) as wpbh,isnull(a.yuan,0)as yuan
,isnull(a.syue,0) as syue,isnull(a.wpbh, b.wpbh) as wpbh2
,isnull(b.yuan,0) as yuan2
from tab1 a
full join tab2 b on a.wpbh = b.wpbh
go
--删除测试环境
drop table tab1,tab2
go
/*--测试结果
wpbh yuan syue wpbh2 yuan2
---------- ----------- ----------- ---------- -----------
01 200 1 01 300
02 300 3 02 0
03 500 5 03 0
04 0 0 04 300(4 row(s) affected)
*/