USE [HCITools] GO IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[aps_Wait_Random_Time]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) DROP PROCEDURE [dbo].[aps_Wait_Random_Time]; GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[aps_Wait_Random_Time] @in_debug tinyint = 0, @in_Minutes smallint AS /*============================================================================= Explication du traitement realise par la SP ------------------------------------------- La SP sert à attendre un temps aléatoire compris entre 0 et une valeur définie Contexte d'utilisation ---------------------- Appelé depuis n'importe quel job Parametres ---------- @in_debug : non utilisé @in_Minutes : temps maximum en minute Creation : 27.10.16 / FLA Modifications : =============================================================================*/ set nocount on; /*------------------- Declaration des variables --------------------*/ declare @delay int, @time datetime, @errno int, @errmsg varchar(255); /*------------ Affectation des parametres aux variables ------------*/ /*-------------------------- Traitement ---------------------------*/ BEGIN TRY select @delay = rand()* 60 * @in_Minutes; select @time = dateadd(ss,@delay, '01.01.1900'); waitfor delay @time; /*---------------------- Traitement des erreurs ----------------------*/ END TRY BEGIN CATCH /* Traitement des erreurs (avec RaiseError) */ EXEC dbo.get_Error_Info; END CATCH GO