日期:2014-05-18 浏览次数:20482 次
if object_id('tb1') is not null drop table tb1 go create table tb1(id int,numb int) insert into tb1 values(1,2) insert into tb1 values(2,3) if object_id('tb2') is not null drop table tb2 go create table tb2(id int,conb int) insert into tb2 values(1,2) insert into tb2 values(1,3) insert into tb2 values(1,4) select tb1.*,tb2.conb from tb1 right join tb2 on tb2.id=tb1.id and tb1.numb =tb2.conb id numb conb ----------- ----------- ----------- 1 2 2 NULL NULL 3 NULL NULL 4 (3 行受影响)
------解决方案--------------------
if object_id('tb1') is not null drop table tb1 go create table tb1(id varchar(10),numb varchar(10)) insert into tb1 values(1,2) insert into tb1 values(2,3) if object_id('tb2') is not null drop table tb2 go create table tb2(id int,conb int) insert into tb2 values(1,2) insert into tb2 values(1,3) insert into tb2 values(1,4) select isnull(a.id,'') id,isnull(a.numb,'') numb,b.conb from tb1 a right join tb2 b on a.id=b.id and a.numb =b.conb id numb conb ---------- ---------- ----------- 1 2 2 3 4
------解决方案--------------------