xml地图|网站地图|网站标签 [设为首页] [加入收藏]

热门视频

当前位置:美高梅游戏网站 > 热门视频 > 美高梅棋牌mssql sqlserver幸免sql脚本中冒出除零荒

美高梅棋牌mssql sqlserver幸免sql脚本中冒出除零荒

来源:http://www.gd-chuangmei.com 作者:美高梅游戏网站 时间:2019-11-01 21:00

摘自:

转自:美高梅棋牌,http://www.maomao365.com/?p=7205

摘要:
下文介绍sql server中,sql脚本避免出现除零错误的方法分享

摘要:


下文分享两条sql求和脚本,再次求和的方法分享

在各种业务系统开发中,通常会遇到除零的错误,下文分享了两种处理方法:
方法1: case when end 

 /*
     例:
       下文已知两条sql求和脚本,现需对两张不同表的求和记录再次求和   
     */  
     ---对两条求和sql脚本求和的方法
      select sum(q) from 
      (
       select sum(qty)  as q from tableNameA where ...
       union all 
        select sum(qty)  as q from tableNameB where ...
       ) as table

     ---对多条求和sql脚本,再次求和的方法分享
     select sum(q) from 
      (
       select sum(qty)  as q from tableNameA where ...
       union all 
        select sum(qty)  as q from tableNameB where ...
         union all 
        select sum(qty)  as q from tableNameC where ...
        union all 
        select sum(qty)  as q from tableNameD where ...
       ...  
    ) as table
declare @a int ---分子
declare @b int ---分母
select  case  when @b=0 then NULL else @a/@b end  as [a除以b]

 

本文由美高梅游戏网站发布于热门视频,转载请注明出处:美高梅棋牌mssql sqlserver幸免sql脚本中冒出除零荒

关键词:

上一篇:SQL SERVER-Delete和Truncate的区别

下一篇:没有了