Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save ALL SPs as files 1

Status
Not open for further replies.

LNBruno

Programmer
Jan 14, 2004
936
US
I know how to do this the hard way; looking for something a bit less labor-intensive (SQL Server 2000).

I can get a list of all stored procedures on the current database like this:
Code:
      SELECT Routine_Name
      FROM Information_Schema.Routines
      WHERE (Routine_Type = 'Procedure' 
         AND Routine_Name NOT LIKE 'dt[_]%'
      ORDER BY Routine_Name

And then change the default destination for Query Analyzer results to "file" (Tools --> Options... --> then select Query Results - SQL Server - General; then select 'Results to file' from the dropdown and set the path for the output).

And run
Code:
sp_helptext ProcedureName
ONE PROC AT A TIME to have it saved off as a .rpt file, but is there a way to execute this for all procs using the proc name as the filename?

Reason for this insanity? Version comparision between code in database and that stored in an external source control.



< M!ke >
I am not a hamster and life is not a wheel.
 
If only...

In their infinite wisdom, the powers that be have seen fit to restrict my access to Query Analyzer...

< M!ke >
I am not a hamster and life is not a wheel.
 
both query analyser and enterprise manager?

--------------------
Procrastinate Now!
 
Code:
[COLOR=blue]declare[/color] @test [COLOR=blue]varchar[/color](200)

[COLOR=blue]SELECT[/color] @test = [COLOR=#FF00FF]MIN[/color](Routine_Name)
      [COLOR=blue]FROM[/color] Information_Schema.Routines
      [COLOR=blue]WHERE[/color] (Routine_Type = [COLOR=red]'Procedure'[/color]
         AND Routine_Name NOT LIKE [COLOR=red]'dt[_]%'[/color])

[COLOR=blue]declare[/color] @lcSQL [COLOR=blue]varchar[/color](8000)
[COLOR=blue]WHILE[/color] @Test [COLOR=blue]IS[/color] NOT NULL
      [COLOR=blue]BEGIN[/color] 
         [COLOR=blue]SET[/color] @lcSQL = [COLOR=red]'sp_helptext '[/color]+@Test
         [COLOR=blue]EXEC[/color] (@lcSQL)
         [COLOR=blue]SELECT[/color] @test = [COLOR=#FF00FF]MIN[/color](Routine_Name)
		        [COLOR=blue]FROM[/color] Information_Schema.Routines
			    [COLOR=blue]WHERE[/color] (Routine_Type = [COLOR=red]'Procedure'[/color]
				       AND Routine_Name NOT LIKE [COLOR=red]'dt[_]%'[/color]
                       AND Routine_Name > @Test)
      [COLOR=blue]END[/color]

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Ok, I keep calling it QA, but I really am using Management Studio...

< M!ke >
I am not a hamster and life is not a wheel.
 
Dynamic SQL! DOH!

Much thanks, Borislav!

< M!ke >
I am not a hamster and life is not a wheel.
 
Nope, it save all in one file. But I think to split file after that is the easier part :)

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Just saw that, Denis. Yes, I do need each one in a separate file to make use of the tool I use for comparison....

Always on Fridays!!! ;-)

< M!ke >
I am not a hamster and life is not a wheel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top