Reputation: 45
I have a stored procedure which is about 4000 lines long; I get a error in line number 699, but I know SSMS takes line number differently. Is there any way to find the exact line number?
Approach I have tried so far.
sp_helptext proc_name
, but this query doesn't executeIs there any way to find out the correct line number ?
Upvotes: 2
Views: 5156
Reputation: 175964
You could check definition in sys.sql_modules:
SELECT *
FROM sys.sql_modules
WHERE object_id = OBJECT_ID('proc_name');
EDIT:
And with split to specific row:
SELECT s.object_id, s.definition, s2.*
FROM sys.sql_modules s
CROSS APPLY (SELECT *, ROW_NUMBER() OVER(ORDER BY 1/0)
FROM STRING_SPLIT(s.definition, CHAR(10))) s2(line, rn)
WHERE object_id = OBJECT_ID('test') -- proc name
AND rn = 5; -- error line
Upvotes: 1