SQL Server 2008 - find out on which row of data an error occurred (divide by zero)

I have a query running on a lot of data in SSMS. After about 20 minutes of execution, the query fails with the "Divide by zero" error (some results have already been returned).

It would be useful to know on which data the error appeared, i.e. find the null id / row number on which the error can be reproduced.

The request itself is quite complex, so I'm not going to publish it; the question is more technical - is there a magazine somewhere or another way to find problem lines?

+3
source share
2 answers
Select
   *,
   Dividend / NULLIF(Divisor, 0) as NullIfBollixedNow
FROM
   MyTable
-- to isolate the rows(s). Without this, you get NULL instead of error in the output
WHERE
    Dividend / NULLIF(Divisor, 0) IS NULL
+2
source

SQL Server , , Put case . -

Select MyFirstField / MySecondField as TestMath
From myTblOfFacts

Select
Case when MySecondField > 0 then MyFirstField / MySecondField
Else -1
End as TestMath
From myTblOfFacts

-1 .

0

Source: https://habr.com/ru/post/1783438/


All Articles