When I use SQL Server and there\'s an error, the error message gives a line number that has no correlation to the line numbers in the stored procedure. I assume that the dif
The long answer: the line number is counted from the CREATE PROCEDURE
statement, plus any blank lines or comment lines you may have had above it when you actually ran the CREATE
statement, but not counting any lines before a GO
statement…
I found it much easier to make a stored proc to play around with to confirm:
GO
-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE ErrorTesting
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT 1/0
END
GO
After you’ve created it, you can switch it to ALTER PROCEDURE
and add some blank lines above the comments and above and below the first GO
statement to see the effect.
One very strange thing I noticed was that I had to run EXEC ErrorTesting
in a new query window instead of highlighting it at the bottom of the same window and running… When I did that the line numbers kept going up! Not sure why that happened..