Tuesday, July 22, 2008

Cursor to fetch all Procedure text in Particular DB

DECLARE @name sysname, @sqlcmd NVARCHAR(400)
DECLARE mycur CURSOR for
SELECT name FROM sys.sysobjects WHERE type ='p'
OPEN mycur
FETCH NEXT FROM mycur INTO @Name
WHILE @@Fetch_Status = 0
BEGIN
SELECT @sqlcmd = N'exec sp_helptext @name'
EXECUTE sp_executesql @sqlcmd, N'@name sysname', @name
FETCH NEXT FROM mycur INTO @name
END
CLOSE mycur
DEALLOCATE mycur

No comments: