Files
sql-scripts/TPDT-268 - ACP in task sequence/dba_storedProcedures/aps_Wait_Random_Time.sql
2024-03-07 16:52:14 +01:00

72 lines
3.5 KiB
Transact-SQL
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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