select 
   case 
     when b = 0 then 0 
     when b <> 0 then cast(a/(b+0.0) as numeric(10,2)) exp1 
   end 
from a

解决方案 »

  1.   

    select 
       case 
         when b = 0 then 0 
         when b <> 0 then cast(a/(b+0.0) as numeric(10,2)) 
       end 
       as exp1 --should be here
    from a
      

  2.   

    select a/(isnull(b,1)+0.0) as c from d
      

  3.   

    select a/(b+0.0) as c from d
    是不是b的数据类型问题。
    select case when b = 0 then 0 else cast(a/(b+0.0) as numeric(10,2)) end exp1 from a
      

  4.   

    int型的数据当你没有设定默认值时也有可能是null所以为了避免这种错误的发生
    一般在进行数据库设计的时候
    数值字段都设计为不允许为空,然后默认值设为0
      

  5.   

    select isnull(a,0)/(isnull(b,0)+0.0)) as c from d