探索与发现

研究java技术

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  83 随笔 :: 0 文章 :: 109 评论 :: 0 Trackbacks

Recently come across yet another SQL statement that required me to check if the denomiator is 0, otherwise the statement returns a devide by zero error.

Naturally, if this was the statement:

SELECT Expression1/Expression2 FROM Table1

You would do something like:

SELECT Expression1/(CASE Expression2=0 THEN XX ELSE Expression2 END) FROM Table1

This might be OK if Expression2 is small, however a better way I discovered is to use a combination of ISNULL and NULLIF
Then it would look like:

SELECT Expression1/ ISNULL( NULLIF(Expression2,0), XX) FROM Table1

Note: you can set the XX to be either NULL or 1 or something else depending on the application of this statement.

posted on 2009-06-03 23:51 蜘蛛 阅读(221) 评论(0)  编辑  收藏 所属分类: SharePoint

只有注册用户登录后才能发表评论。


网站导航: