Hi,I'm using SQLServer 2008 and I want to get somebody else's opinion on this issues.I have the following SQL query: select T1.value1 , T1.value2 from T1 where not exists (select 1 from T2 where T2.id = T1.id and T2.year = T1.year) and T1.batch = 163 order by T1.value2 asc
This returns the following results:313.000000000000 486.628500000000380.000000000000 590.795000000000701.900000000000 1091.260600000000...
However if I modify the query thus: select T1.value1 / T1.value2
I get:Msg 8134, Level 16, State 1, Line 2Divide by zero error encountered.
Now if I remove the not exists from the original query the zero in the value2 column shows up. What appears to be happening is the divide is being applied before the filtering of the where clause.Is this the correct behaviour? I've not stumbled upon this issue before or is there no guarantee in the order that these things happen and this is a side effect of an optimisation?Is this possible in DB2/Oracle and MySQL or a SQLServer specific issue?Thoughts opinions gratefully welcomed.