How can I get the actual stored procedure line number from an error message?

前端 未结 9 2396
长情又很酷
长情又很酷 2020-12-04 07:02

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

9条回答
  •  萌比男神i
    2020-12-04 07:16

    Actually this Error_number() works very well.

    This function starts counts from the last GO (Batch Separator) statement, so if you have not used any Go spaces and it is still showing a wrong line number - then add 7 to it, as in stored procedure in line number 7 the batch separator is used automatically. So if you use select Cast(Error_Number()+7 as Int) as [Error_Number] - you will get the desired answer.

提交回复
热议问题