Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

script for enabling notification(mail alert and write to event log for SQL server agent job properties

$
0
0

Can some one please share the script for checking the notification enabled  or not on job properties of SQL agent.

ALso provide me any scirpt for altering the job properites . I have tried as like below but not getting exact result what we expected

Please see if this idea is correct ?

declare @jobnameIdnvarchar(100)

declare @notify_level_eventlogint

     declare @notify_level_email  int

           declare @notify_email_operator_id nvarchar(100)

           DECLARE @vSQL NVARCHAR(MAX)

set @notify_level_eventlog= 3;

set @notify_level_email=3;

set @notify_email_operator_id= 1;

begin

     begin

     declare jobcursor  cursorforselect  jobnameId= jobs.job_id,notify_level_eventlog,notify_level_email,

      notify_email_operator_idfrom

msdb.dbo.sysjobs jobs(nolock)where category_id in(10,11,12,13,14,15,16,17,18,19,20)

and notify_level_eventlog!=2 and notify_level_email!=2

    end

      open jobcursor

fetchnextfrom jobcursorinto @jobnameId,@notify_level_eventlog,@notify_level_email,@notify_email_operator_id 

WHILE@@FETCH_STATUS= 0

begin

select'****************************************************************************************'

select @jobnameId,@notify_level_eventlog,@notify_level_email,@notify_email_operator_id

SET @vSQL='EXEC msdb.dbo.sp_update_job  @job_id =@jobnameId,@notify_level_eventlog=3,@notify_level_email=3,@notify_email_operator_name= xxxxx'

     EXECsp_executesql  @vSQL

           

fetchnextfrom jobcursorinto @jobnameId,@notify_level_eventlog,@notify_level_email,@notify_email_operator_id 

end

close jobcursor

deallocate jobcursor

end


-



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>