In the following example (22: 20
) Execute the Stored ProcedureSp_update_job
. Use MSDB;
Execute Sp_add_job @ Job_name = ' Testjob ' ;
Begin Waitfor Time ' 22: ' ;
Execute Sp_update_job @ Job_name = ' Testjob ' , @ New_name = ' Updatedjob ' ;
End ;
Go
In the following example, the stored procedure is executed after two hours of delay. Note: delay cannot exceed 24 hours at most
Begin
WaitforDelay'';
ExecuteSp_helpdb;
End;
Go
Use Adventureworks2008r2; Go If Object_id ( ' DBO. timedelay_hh_mm_ss ' , ' P ' ) Is Not Null Drop Procedure DBO. timedelay_hh_mm_ss; Go Create Procedure DBO. timedelay_hh_mm_ss ( @ Delaylength Char ( 8 ) = ' 00:00:00 ' ) As Declare @ Returninfo Varchar ( 255 ) If Isdate ( ' 2000-01-01 ' + @ Delaylength + ' . 000 ' ) = 0 Begin Select @ Returninfo = ' Invalid time ' + @ Delaylength + ' , HH: mm: SS, submitted. ' ; -- This print statement is for testing, not use in production. Print @ Returninfo Return ( 1 ) End Begin Waitfor Delay @ Delaylength Select @ Returninfo = ' A total time ' + @ Delaylength + ' , HH: mm: SS, has elapsed! Your time is up. ' -- This print statement is for testing, not use in production. Print @ Returninfo ; End ; Go /* This statement executes the DBO. timedelay_hh_mm_ss procedure. */ Exec Timedelay_hh_mm_ss ' 00:00:10 ' ; Go