Is there a function or keyword that will allow me to get the current line number in a stored procedure?
I know there's an undocumented LineNo
function that allows you to set the line number, and affect the output of system error messages
https://stackoverflow.com/questions/4054511/what-exactly-does-the-t-sql-lineno-reserved-word-do
I know there's a function ERROR_LINE()
that's available inside of a BEGIN CATCH ... END CATCH
.
ERROR_LINE()
does what I need, but I want to use it from outside a CATCH block. Anywhere in the file.
DECLARE @InsertSource VARCHAR(1000) = object_name(@@procid)
EXEC PROC_Accounting_Transaction_Insert ... other parameters..., @InsertSource
Currently I'm just hard-coding the call # as it appears in the stored procedure body, but it's getting old quickly.
DECLARE @InsertSource VARCHAR(1000)
SET @InsertSource = object_name(@@procid) + '#1'
EXEC ...
SET @InsertSource = object_name(@@procid) + '#2'
EXEC ...
#1
, etc as those markers will still be relevant as you add/remove/change code in this Stored Proc (assuming you never re-assign one of those call numbers).