There is a temporary table of the following form:
CREATE TABLE #1 ( num1 FLOAT ,num2 FLOAT ) INSERT INTO #1 SELECT 0 ,0 INSERT INTO #1 SELECT 0 ,1 INSERT INTO #1 SELECT 1 ,0 INSERT INTO #1 SELECT 1 ,1 I execute the following request and it falls with an error:
SELECT * FROM #1 a WHERE ( a.num1 > 0 AND a.num2 = 0 ) OR ( a.num1 > 0 AND a.num2 > 0 AND a.num1 / a.num2 >= 2 ) OR ( a.num1 >= 0 AND a.num2 < 0 ) Divide by zero error encountered.
I smoked a certificate, it says that the division operation is performed before all logical operations. Ok, now it became clear why falls with an error. But then I remove the "=" sign from the last condition and everything works:
SELECT * FROM #1 a WHERE ( a.num1 > 0 AND a.num2 = 0 ) OR ( a.num1 > 0 AND a.num2 > 0 AND a.num1 / a.num2 >= 2 ) OR ( a.num1 > 0 AND a.num2 < 0 ) Looked at the query execution plan: 
Judging by the query execution plan, the division by zero error should have reappeared. But that did not happen. Checked on Microsoft SQL Server version 2005 and 2012. The problem is this everywhere present. In Teradata, the first request works without problems.
My question is not how to rewrite the request to make it work, but WHY it works. Why, when in the second query I remove the "=" sign, the query works without problems?
