Wrong Line Number reported in SQL Message Window

Posted on 2012-09-03
Medium Priority
Last Modified: 2012-09-03
I am getting the following message when I run a procedure in SQL
Msg 8626, Level 16, State 1, Line 10

My script has over a 1000 lines of SQL in it and the message in not related to line 10 of the script.  Any suggestions on how to get the actual line number for the message?
Question by:bkjenner
  • 3
  • 2
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38361513
The line number is always relative and closest to the start of the query with the error.

Try posting the relevant part of the code, the error message and we may be able to help you more.

Author Comment

ID: 38361678
I wasnt so much looking help with the error message but more wondering how when you have a long sql script with multiple GO statements in it, how can you easily determine the line number for error messages.
LVL 75

Accepted Solution

Anthony Perkins earned 2000 total points
ID: 38361778
As I stated before the Line Number is relative, so you may think this is wrong. but if you have something like this:
SELECT * FROM ValidTable

What do you think the line number for the error "Divide by zero error encountered" should be?  If you thought it should be 3, you would be wrong.  It is 0.

Here is what I suggest you do as a technique for debugging.  Next time you get an error, ignore the line number, especially if you are using GO command, but instead double click on the error.  It will take you to the line that generated the specific error.

Author Comment

ID: 38361952
Thanks for your help! Works great
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38362124
And this:
It is 0.
Should of course have read:
It is 1.

Thanks for the points.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question