Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RichardHan/1ff2617db7de294d8367c158cfae4796 to your computer and use it in GitHub Desktop.
Save RichardHan/1ff2617db7de294d8367c158cfae4796 to your computer and use it in GitHub Desktop.
Get all stored procedure code to one column
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