[SQL Server] Activer/Désactiver des jobs SQL Server
-- =============================================
-- Author: Zouhaier KHARROUBI
-- Create date: 12/07/2019
-- Description: Activer/Désactiver des jobs SQL Server
-- =============================================
DECLARE @NWhere AS NVARCHAR(150)='Import Commandes_%'
,@Requete AS NVARCHAR(MAX)=''
,@enabled AS TINYINT= 0 -- 0 : Désactiver le job / 1 : Activer le job
-- Afficher la liste des jobs SQL Server à traiter
SELECT name AS Nom_Job, Requete = 'EXEC msdb.dbo.sp_update_job @job_id = '''
+ CAST(job_id AS NVARCHAR(250))
+ ''', @enabled = '+CAST(@enabled AS NVARCHAR(1))+';'
FROM [msdb].[dbo].[sysjobs] WHERE [name] LIKE @NWhere
SELECT @Requete = @Requete +'EXEC msdb.dbo.sp_update_job @job_id = '''
+ CAST(job_id AS NVARCHAR(250))
+ ''', @enabled = '+CAST(@enabled AS NVARCHAR(1))+';'
FROM [msdb].[dbo].[sysjobs] WHERE [name] LIKE @NWhere
EXECUTE sp_executesql @Requete