create table A(银行卡号 varchar(5),金额 int,日期 datetime,交易号 varchar(100)) insert into A select 'xxxx1','100',getdate(),'001' union all select 'xxxx2','200',getdate(),'002' union all select 'xxxx3','300',getdate(),'003' union all select 'xxxx4','400',getdate(),'004' create table B(银行卡号 varchar(5),金额 int,日期 datetime,交易号 varchar(100)) insert into B select 'xxxx1','100',getdate(),'001' union all select 'xxxx5','200',getdate(),'002' union all select 'xxxx3','400',getdate(),'003' union all select 'xxxx4','400',getdate(),'005' select (case when A.交易号 is null then 'B表多' when B.交易号 is null then 'A表多' when A.银行卡号!=B.银行卡号 then '卡号不一致' when A.金额!=B.金额 then '金额不正确' else '正确' end) as 比较结果, isnull(a.交易号,b.交易号) as 交易号, isnull(a.日期 ,b.日期 ) as 日期 , a.银行卡号, a.金额 , b.银行卡号, b.金额 from A full outer join B on A.交易号=b.交易号