create table ta(id int,col varchar(10))insert into ta select 1,'fsadf'create table tb(id int,col varchar(10))insert into tb select 1,'fsadf' insert into tb select 2,'sdfas' insert into tb select 3,'fete' select A.*,isnull(B.col,0) bcol from tb A left join ta B on A.id = B.id /* id col bcol ------------------ 1 fsadf fsadf 2 sdfas 0 3 fete 0*/ drop table ta,tb
这个是正确的。我也遇到过。就是这样就能解决。codeSELECT 字段ISNULL(字段,'0') FROM TB 里面就全部是0了
insert @t select null
insert @t select 1
insert @t select 2
select isnull(ID,0) from @t
insert into tb select 2,'sdfas'
insert into tb select 3,'fete'
select A.*,isnull(B.col,0) bcol from tb A left join ta B on A.id = B.id
/*
id col bcol
------------------
1 fsadf fsadf
2 sdfas 0
3 fete 0*/
drop table ta,tb