设为首页 加入收藏

TOP

mssql sqlserver避免sql脚本中出现除零错误的方法分享
2019-09-03 00:34:56 】 浏览:21
Tags:mssql sqlserver 避免 sql 脚本 出现 错误 方法 分享

摘自:http://www.maomao365.com/?p=6612

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


在各种业务系统开发中,通常会遇到除零的错误,下文分享了两种处理方法:
方法1: case when end 
declare @a int ---分子
declare @b int ---分母
select  case  when @b=0 then NULL else @a/@b end  as [a除以b]
 
  
方法2:nullif
nullif(表达式A,表达式B)
—-如果表达式A不等于表达式B,则返回表达式A
—-反之返回NULL 

 

declare @a int ---分子
declare @b int ---分母
select @a/nullif(@b,0) as [a除以b]

 

 
 
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MsSQL使用加密连接SSL/TLS 下一篇PostgreSQL的表空间

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目