Tips For Debugging Large Procedures
Erik Darling has a few hints for debugging large stored procedures in SQL Server:
Tip #1: Format Your Code
There’s no shortage of free and paid tools out there. This list from the Recently Legendary Aaron Bertrand on Stack Exchange has both.
This one alone is great. Erik has several other tips as well.