• From what understand about your problem your only objective is to script the procedure with the output to be printed to text.

    If you don't need to specifically have the output to text, I would suggest just using the following: exec sp_helptext 'sp_name' and copy and paste it from the normal grid results.

    If you need to specifically print to text, have a look at the attached script also using sp_helptext and see if it works for you. I created this script to be able script multiple or single procedures at a time with some added options. The only limitation of this script is that if you have a single line of code in the procedure exceeding 255 characters, it will split the string. As a standard I do not think that this will be an issue, but if it is, I have a solution for that as well, but only if needed.

    If you need a more specific solution I might already have a solution available, but just give this a try first.