标签集

Null 如何进行运算

视图   ViewMain   有数据如下:  
   
  ----------------------  
  a                 b  
  ----------------------  
  30               20  
  100           Null  
  ----------------------  
  当使用Select   (a-b   )   as   TotalMoney   From   ViewMain     得到如下结果  
  ----------------------  
  TotalMoney  
  ----------------------  
  10  
  Null  
  ----------------------  
  当b=Null   时   100-Null   还是Null   ,能不能把Null转换为0,使其结果为:  
  100-Null=100    
   
null和任何值直接运算都是null,必须用isnull函数转换
isnull(b,   0):  
  Select   isnull(a,0)-isnull(b,0)   as   TotalMoney   From   ViewMain


Select   (isnull(a,0)   -   isnull(b,0))   as   TotalMoney   From   ViewMain

posted on 2009-11-04 21:52  宋亚奇  阅读(477)  评论(0编辑  收藏  举报

导航