Avatar of Tessando
TessandoFlag for United States of America

asked on 

How Can I Setup a SQL Job Step Alert on SQL 2016?

I am running SQL Server 2016 on Windows Server 2016 and have two large SQL Jobs. One runs in the early morning and one in the evening.

I've already setup Database mail and have tested successfully, so I get email alerts for completed jobs. I'd like to go a layer deeper.

I'd like to create an email alert if a job runs over a certain amount of time. There are 15 steps in this particular SQL Job, but a handful of them get hung-up often (mostly because some folks are allowed to upload Excel docs that the Job updates).

Is there a way to create a New Alert such that a given job step would send me a notification if it took over a certain amount of time? (e.g. ~30 minutes).

Thanks for your help.


...
Microsoft SQL ServerWindows OSSQL

Avatar of undefined
Last Comment
Tessando
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

There is no built-in alert in SQL that does that.  You'd have to write code yourself to do that.
ASKER CERTIFIED SOLUTION
Avatar of D B
D B
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
I'd start the monitoring job within the main job.  That way you can change the main job schedule without having to remember to adjust other job(s).

The other job could delay the amount of time passed to it to delay, such as 120 minutes, or just always delay a fixed amount of time, whichever you prefer (I like the first method, but you may prefer the second).
Avatar of D B
D B
Flag of United States of America image

Scott: Have you found a way to pass a parameter to a job?
Yep.  Update the description on the receiving job by concatenating the control values to the existing desc.  When that job starts, it reads its own description (from msdb.dbo.sysjobs) to get the passed info.  Something like DELAY=120 should be sufficient, and would easily allow values to be passed too.  The receiving can also remove the params it used, to free space for the next time it needs called.

I thought maybe with SQL 2016 this wouldn't be necessary, because  of SESSION_CONTEXT(), but I realized the new job would be a new session, so that wouldn't work and would have to do it my "old school" way.
Avatar of D B
D B
Flag of United States of America image

I think he is going to have to kick off the second job from the first, using sp_start_job in the first step, and the second job is going to have to have a WAITFOR DELAY '02:00:00' (e.g. to wait 2 hours) before checking to see if the first job is still running.
Exactly, as I stated.  Except that I would also pass the delay interval in, in case it changes in the future, or based on the specific data being processed that run.  Or if for some reason the first job started late, or to control other aspects of the second job, etc..
Avatar of Tessando
Tessando
Flag of United States of America image

ASKER

Thanks for everyone's suggestions. I wish this was something that Microsoft had built in, but this work-around is going to fit in nicely. Thanks again for your contribution.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo