Line number in error message doesn't match up with line number in code

  • Hi everyone

    I have a 1000 plus line query and I am getting an error:

    Msg 8115, Level 16, State 6, Procedure dbo.TestQuery, Line 1036 [Batch Start Line 2]
    Arithmetic overflow error converting float to data type numeric.

    It says line 1036 but when I go to that line I get something that can't possible cause an error.  Line 1036 is part of a comment.

    Is there a way to know the actual line that caused the failure?  That way I can troubleshoot the issue.

    Thank you

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • I think you need to ignore the header piece with the CREATE statement, and start the line numbering at the top of the actual procedure code

  • also note that if a long statement is in use, like WITH MyCTE..... or a cursor, the error returns the first line of the statement, and not the in between line where the error actually occurred, you'll want to break down the offending query, but you should be able to find any column or calculation that would return a float, right? and explicitly cast it if needed?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • If this is in SSMS, I often double click the error and it jumps to the line, which usually gets me close enough to figure out what is wrong.

    The other thing you might try is pasting this into an LLM (if you are allowed), which might spot a syntax error

     

  • This is a classic problem with where to start counting.  It's compounded by the fact that when people generate the code for modification, it frequently adds a blank line above the CREATE statement.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I use the (undocumented) LINENO command when testing my stored procedures. This makes the line reported in the error correspond more exactly to the code.

    lineno

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply