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
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.