DBArtisan can't help in this case. It simple does not work correct.
I remember I wrote my own script in TSQL. But that was many time ago. I recall that I used with variable VARCHAR(MAX) to place in it an SP.
Sorry, can't help with the script - I simple have not saved it.