left join时,a表存在,b表中不存在的就会出现null,用函数isnull(字段,0)处理一下即可

解决方案 »

  1.   

    SELECT 字段ISNULL(字段,'') FROM TB
      

  2.   

    用函数isnull(字段,0)处理一下即可
      

  3.   

    declare @t table(ID int)
    insert @t select null
    insert @t select 1
    insert @t select 2
    select isnull(ID,0) from @t
      

  4.   

    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
      

  5.   

    这个是正确的。我也遇到过。就是这样就能解决。codeSELECT 字段ISNULL(字段,'0') FROM TB 里面就全部是0了