<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Handling Division By Zero Scenarios in T-SQL</title>
	<atom:link href="http://www.sqlmusings.com/2009/05/09/handling-division-by-zero-scenarios-in-t-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sqlmusings.com/2009/05/09/handling-division-by-zero-scenarios-in-t-sql/</link>
	<description>ramblings, discoveries, tutorials on sql server and other database stuff</description>
	<lastBuildDate>Wed, 25 Jan 2012 06:55:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Derek</title>
		<link>http://www.sqlmusings.com/2009/05/09/handling-division-by-zero-scenarios-in-t-sql/comment-page-1/#comment-6049</link>
		<dc:creator>Derek</dc:creator>
		<pubDate>Tue, 10 Jan 2012 16:19:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/?p=725#comment-6049</guid>
		<description>@Peter North Maybe that&#039;s due to the way SQL Server treats (ignores) NULLs when aggregating.</description>
		<content:encoded><![CDATA[<p>@Peter North Maybe that&#8217;s due to the way SQL Server treats (ignores) NULLs when aggregating.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete North</title>
		<link>http://www.sqlmusings.com/2009/05/09/handling-division-by-zero-scenarios-in-t-sql/comment-page-1/#comment-5888</link>
		<dc:creator>Pete North</dc:creator>
		<pubDate>Wed, 28 Sep 2011 15:16:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/?p=725#comment-5888</guid>
		<description>None of that works on something like this...
                          

(SELECT     SUM(Cost) AS Expr1
                            FROM          dbo.qry_367costs AS x
                            WHERE      ([Week No] = dbo.qry_367costs.[Week No]) AND (Year = dbo.qry_367costs.Year)) /
                          (SELECT     COUNT(TransID) AS Expr1
                            FROM          dbo.qry_sitecISQ AS qry_sitecISQ_2
                            WHERE      (Tinweek = dbo.qry_367costs.[Week No]) AND (Tinyear = dbo.qry_367costs.Year)) AS AvgCPQ</description>
		<content:encoded><![CDATA[<p>None of that works on something like this&#8230;</p>
<p>(SELECT     SUM(Cost) AS Expr1<br />
                            FROM          dbo.qry_367costs AS x<br />
                            WHERE      ([Week No] = dbo.qry_367costs.[Week No]) AND (Year = dbo.qry_367costs.Year)) /<br />
                          (SELECT     COUNT(TransID) AS Expr1<br />
                            FROM          dbo.qry_sitecISQ AS qry_sitecISQ_2<br />
                            WHERE      (Tinweek = dbo.qry_367costs.[Week No]) AND (Tinyear = dbo.qry_367costs.Year)) AS AvgCPQ</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manfred Sorg</title>
		<link>http://www.sqlmusings.com/2009/05/09/handling-division-by-zero-scenarios-in-t-sql/comment-page-1/#comment-5589</link>
		<dc:creator>Manfred Sorg</dc:creator>
		<pubDate>Wed, 30 Jun 2010 05:03:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/?p=725#comment-5589</guid>
		<description>These approaches will surely avoid Division by Zero errors - but they do not solve the problem. Usually you should ask yourself why there is a /0-problem. If you have this answer you can query if it is a querying fault (in many cases) or if it happens by design.
In the first case you should optimize your query and only in the latter case you should handle the issue by asking you which result you are expecting when the problem occurs. That&#039;s when you use the above mentioned techniques.
@Gary: If you solved a /0-problem and it&#039;s still there you have another one. It can be in the order by clause or somewhere else. It is even possible that a subquery results 0 records while you are expecting more ...</description>
		<content:encoded><![CDATA[<p>These approaches will surely avoid Division by Zero errors &#8211; but they do not solve the problem. Usually you should ask yourself why there is a /0-problem. If you have this answer you can query if it is a querying fault (in many cases) or if it happens by design.<br />
In the first case you should optimize your query and only in the latter case you should handle the issue by asking you which result you are expecting when the problem occurs. That&#8217;s when you use the above mentioned techniques.<br />
@Gary: If you solved a /0-problem and it&#8217;s still there you have another one. It can be in the order by clause or somewhere else. It is even possible that a subquery results 0 records while you are expecting more &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary</title>
		<link>http://www.sqlmusings.com/2009/05/09/handling-division-by-zero-scenarios-in-t-sql/comment-page-1/#comment-5560</link>
		<dc:creator>Gary</dc:creator>
		<pubDate>Wed, 05 May 2010 18:38:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/?p=725#comment-5560</guid>
		<description>I&#039;ve been searching the net for this kind of solution. While i&#039;m sure your solution works, however, it doesn&#039;t seem to work in my situation. My divide by zero occurs in a SQL Server view when i try to find the MOD (remainder) of 2 columns. In very few instances the divisor is 0. By trying to apply the concepts you show i still get the devide by 0 error. Any suggestions for use in a view?</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been searching the net for this kind of solution. While i&#8217;m sure your solution works, however, it doesn&#8217;t seem to work in my situation. My divide by zero occurs in a SQL Server view when i try to find the MOD (remainder) of 2 columns. In very few instances the divisor is 0. By trying to apply the concepts you show i still get the devide by 0 error. Any suggestions for use in a view?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

