Discussion Locked

Create a Stored Procedure

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How can I create a stored procedure that creates several stored procedures.

Any help or reference will be usefull

Thanks

5 replies

by chrandrob

You need to build the stored procedure(s) that will be created as a text string and then execute it. Below is a sample stored procedure (named ProcMaker) that will create 10 other stored procedures named ProcMaker1 through ProcMaker10 when executed:

CREATE PROCEDURE dbo.ProcMaker AS

Declare @SQL varchar(1000),
@ProcNum int

Set @ProcNum = 0

While @ProcNum < 10
BEGIN
Set @ProcNum = @ProcNum + 1
Set @SQL = 'Create Procedure dbo.ProcMaker' + Cast(@ProcNum AS varchar) + ' AS'

Exec(@SQL)
END

This discussion is closed to new replies.