get the text of a stored procedure into a variable in SQL Server

前端 未结 3 1318
天命终不由人
天命终不由人 2021-01-18 07:10

I want to loop through several stored procs and extract one string form each of them to use in another procedure (basically the 4-part remote server string)

So I can

3条回答
  •  深忆病人
    2021-01-18 07:32

    Nicholas Carey's third option needs some changes,

    object_definition function needs object_id as parameter,

    so the code should be

    declare @source_code varchar(max)
    declare @objectid int
    select @objectid=object_id('dbo.my_stored_procedure_name')
    select @source_code = object_definition(@objectid )
    

    Check to this link more details https://msdn.microsoft.com/en-IN/library/ms176090.aspx

提交回复
热议问题