To Exec a Procedure Dynamically


Executing a Procedure Dynamically

If you want to Execute a Procedure Dynamically using Another Procedure,

Example you need to Exec a Procedure with the following Dates,
Consider Each SP takes 1 hour to Execute

'21/09/2009'
'22/09/2009'
'23/09/2009'
'24/09/2009'
'25/09/2009'
'26/09/2009'
'27/09/2009'

Then you Don't need to stick on and execute each Sp, you can Simply Write a Batch statement to Execute all the Sp's,


DECLARE @S AS VARCHAR(2)
DECLARE @STR AS VARCHAR(250)
DECLARE @STR1 VARCHAR(200)
DECLARE @STR2 VARCHAR(200)
SET @S=21
SET @STR1='SP_NAME'
WHILE @S <= 27
BEGIN
SET @STR2=@S+'/09'+'/2009'
SET @STR= @STR1+SPACE(1)+CHAR(39)+@STR2+CHAR(39)--This Char(39) will give '
EXEC(@STR)
PRINT @STR
SET @S=@S+1
END


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: