For performance reasons, the SQL Prompt parser only looks back a certain number of characters to find variable declarations.
By default, this is 5000 characters, but if you are happy editing XML files then it can be changed:
1. Open up "%LOCALAPPDATA%\\Red Gate\\SQL Prompt 5\\RedGate_SqlPrompt_Engine_EngineOptions.xml" in a text editor.
2. Find the tag <ParserLookBackDistance>.
3. Increase the number in the tag from 5000 to something bigger like 30000.
Please be aware that very large values of this option have not been thoroughly tested and may cause performance degradation, so use with caution.
Red Gate Software