Last active
April 20, 2016 08:59
-
-
Save RichardHan/1ff2617db7de294d8367c158cfae4796 to your computer and use it in GitHub Desktop.
Get all stored procedure code to one column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE c CURSOR READ_ONLY FAST_FORWARD FOR | |
SELECT name | |
FROM dbo.sysobjects | |
WHERE (type = 'P') and name not like 'sp_%' order by name | |
DECLARE @name nvarchar(255) | |
declare @result varchar(MAX) | |
set @result = '' | |
-- Open the cursor | |
OPEN c | |
FETCH NEXT FROM c INTO @name | |
WHILE (@@FETCH_STATUS = 0) | |
BEGIN | |
if (OBJECT_ID(@name) is not null) | |
set @result = @result + (SELECT OBJECT_DEFINITION (OBJECT_ID(@name))) + CHAR(13) | |
FETCH NEXT FROM c INTO @name | |
END | |
-- Close and deallocate the cursor | |
CLOSE c | |
DEALLOCATE c | |
select @result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment