title: How to identify row in query results that is causing fatal error?
body: <p>My query runs for awhile (outputting rows) and then stops, erroring out with:</p>
  
  <blockquote>
    <p>Msg 8115, Level 16, State 8, Line 5 Arithmetic overflow error
    converting int to data type numeric.</p>
  </blockquote>
  
  <p>That doesn't tell me WHICH row (of the rowset formed by the FROM clause - NOT which row in the SQL query) is causing this error.</p>
  
  <p>I used old trick of going to Query Options and unchecking "set arithabort" and "set ansi_warnings", which causes the query to keep running and put a NULL in the offending cell.</p>
  
  <p>The problem is that the result set can correctly have a NULL in a lot of places, so this doesn't help. (and the error message is equally vague: "Arithmetic overflow occurred.")</p>
  
  <p>I'm racking my brain on trying to figure this out - I've thought of using cursors or loops, but there are issues with each.</p>
  
  <p>What do you guys do when you get an error like this, in order to find out which row is causing it?</p>
  
  <p>UPDATE: Thanks for the helpful suggestions below; they are great and work well.  However, before going to that trouble (there are alot of columns in this query), I just wanted to SEE the row that was causing the error.  Luckily, I guessed that the last row in the query result set was the row right before the error occurred.  When I raw a query to see the data right below that row (minus the calculated fields of course), I immediately noticed a larger-than-normal value in one of the INT fields.</p>
  
  <p>This seems like a good first step before going to the trouble of writing queries like the ones below - but thanks, I will save those and surely need them later when the problem isn't this obvious upon looking at the offending data.</p>