I have 40 or so stored procedures that i would like to be able to print out and refactor on paper then make the changes to the procedures. I have come across a couple of different possibilities but none so far that fit what I want but a little tweaking may fix that. the first
select
text
from
syscomments
where
id in (select id from sysobjects where xtype='p' and name LIKE 'qscore_Corp%')
but this returns all the code unformatted on single lines.
using sp_helptext is an option also but i have not figured out how to concatenate multiple into one long table of text.
My goal is to make it so that I can print the source of these 40 procedures from one text file with the formatting i have used in each procedure.
SOLVED::: By Martin thanks again.
I made a small tweak to his solution that pulled the procs i needed.
DECLARE @stored_procedure_code nvarchar(MAX)
SET @stored_procedure_code = ”
SELECT @stored_procedure_code = @stored_procedure_code + '' + ISNULL(OBJECT_DEFINITION(object_id),'')
FROM sys.procedures WHERE name LIKE 'qscore_Corp%'
SELECT @stored_procedure_code AS [processing-instruction(x)] FOR XML PATH('')
Something Like