﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Cursor to generate Stored procedures Script / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 17:26:49 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Cursor to generate Stored procedures Script</title><link>http://www.sqlservercentral.com/Forums/Topic1394910-391-1.aspx</link><description>I would basically do it the same as anthony; they are already in a table, so not temp table or cursor required.I kind of like some of the built in functions, so I'd use those for schema/object name:[code]select   OBJECT_SCHEMA_NAME(object_id) AS SchemaName,  OBJECT_NAME(object_id)        AS ObjectName,  definition                    AS ObjectDefinitionFROM sys.sql_modules [/code]</description><pubDate>Tue, 11 Dec 2012 05:34:59 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: Cursor to generate Stored procedures Script</title><link>http://www.sqlservercentral.com/Forums/Topic1394910-391-1.aspx</link><description>Or just query the sys.sql_modules table[code="sql"]select o.name,sm.definitionfromsys.objects oinner joinsys.sql_modules smono.object_id = sm.object_idwhereo.type = 'p'[/code]</description><pubDate>Tue, 11 Dec 2012 03:20:01 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>RE: Cursor to generate Stored procedures Script</title><link>http://www.sqlservercentral.com/Forums/Topic1394910-391-1.aspx</link><description>You might also try this with a TVF.[code="sql"]CREATE FUNCTION dbo.FnGetDefinition(@ObjId INT)RETURNS @DefTable TABLE(ObjectDef VARCHAR(MAX))ASBEGININSERT INTO @DefTable SELECT object_definition(@ObjID)RETURNEND;GOSELECT P.name,D.ObjectDef  FROM sys.procedures As PCROSS APPLY dbo.FnGetDefinition(p.object_id) As D[/code]</description><pubDate>Tue, 11 Dec 2012 02:10:40 GMT</pubDate><dc:creator>sharky</dc:creator></item><item><title>RE: Cursor to generate Stored procedures Script</title><link>http://www.sqlservercentral.com/Forums/Topic1394910-391-1.aspx</link><description>I am using temp table instead of cursor.declare @spname varchar(100), @sptext varchar(max), @cnt int, @i intselect @spname = '', @sptext = '', @cnt = 0, @i = 1;create table #spnames(id int identity(1,1), spname varchar(100))insert into #spnames(spname)select distinct schema_name(schema_id) + '.' + name from sys.objects where type = 'P'select @cnt = count(1) from #spnameswhile (@i &amp;lt;= @cnt)begin  select @spname = spname from #spnames where id = @id  select @sptext = object_definition(object_id) from sys.objects where  = schema_name(schema_id) + '.' + name = @spnameprint @sptext  set @i = @i+iendGOdrop table #spnames</description><pubDate>Tue, 11 Dec 2012 00:16:47 GMT</pubDate><dc:creator>Prassad Dabbada V R</dc:creator></item><item><title>Cursor to generate Stored procedures Script</title><link>http://www.sqlservercentral.com/Forums/Topic1394910-391-1.aspx</link><description>Hi Team,is it possible to get all stored procedures script using a cursor.Can u please provide the query</description><pubDate>Tue, 11 Dec 2012 00:05:31 GMT</pubDate><dc:creator>Minnu</dc:creator></item></channel></rss>