只要在计算这个字段的时候使用函数 ISNULL(字段名,0)这个函数判断 字段 是否为NULL,假如是NULL则返回0,否则返回这个字段的值!

解决方案 »

  1.   

    select t1.col1 as name,t1.col2 as col1,t2.col2 as col2,t3.col3 as col3,(ISNULL(t1.col2,0) - ISNULL(t2.col2,0) - ISNULL(t3.col2,0)) as col4   from t1 left join  t2 on t1.col1 = t2.col1
               left join  t3 on t1.col1 = t3.col1
      

  2.   

    另外,大力斑竹的《数据库设计规范》中建议,“对数据列,不可为空,以0作默认值”,这样不会发生问题了。
    因为
    -------------------------------------------------------------------------------
    回复人: pengdali(大力 V3.0) ( ) 信誉:536  2003-9-9 18:31:21  得分:0 
    如果不使用 isnull、is not null、is null
    null与任何数运算结果为null
    null与任何值比较结果为假
    用not in 对null操作有bug
    -------------------------------------------------------------------------------
    http://expert.csdn.net/Expert/topic/2241/2241538.xml?temp=.5691187 
    http://expert.csdn.net/Expert/topic/1959/1959120.xml?temp=.6873133