Category: Blog

  • Register for the 2021 PASS Data Community Summit

    Registration for the 2021 PASS Data Community Summit opened today. This year’s event is virtual on November 8-12, and you can register for free.

    That’s right, free. No cost, just the time, which is something you might point out to your boss to get some time that week to attend.

    Join me and see my sessions, or any of the others that have been selected. There are plenty of great ones to choose from. Register today and I’ll see you online in November.

    2021_Speaking_Summit

  • Daily Coping 19 Aug 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to if someone annoys you, be kind. Imagine how they are feeling.

    I was in a meeting recently, and someone was a little annoying to me. In this case, it wasn’t what they did, but rather what they didn’t do, which was be prepared or communicate well. Time is valuable to me, I hate Zoom meetings more than I expected, and I sometimes find myself losing some patience when there aren’t productive presentations or discussions.

    I did find patience, and I considered just how the person might have had a bad week. They might be struggling. In fact, in this case, I knew the person had some issues outside of work, so I accepted the less than efficient meeting. Asked questions, was pleasant, and voiced no complaints.

    We go through, things worked out, and it wasn’t a big impact to my day. I didn’t let it, and more importantly, I didn’t ruin anyone else’s day.

  • Finding Failed Job Steps

    Kendra’s query was a good starting point, and I used most of it in the first CTE shown below. This query basically looks at msdb.dbo.sysjobhistory and msdb.dbo.sysjobactivity, joining them on the job_id, which is the PK. However, we are only looking at steps, which is anything with a step_id > 0. The step_id = 0 is for the overall job.Recently a customer was asking for a way to alert on job steps that failed, but the job succeeded. They really wanted a custom metric for SQL Monitor, which I submitted, but this post looks at the query in general, trying to determine if a job step failed.

    Note: Let me start by noting that this is based on work by Kendra from her post, SQL Agent Jobs: Checking for failed steps at the end of a job.

    Based on Kendra’s query, I looked through what is happening in msdb.dbo.sysjobhistory and msdb.dbo.sysjobactivity. In Kendra’s query, she is looking for a specific job, but I wanted all jobs. This lead me to build a CTE that queries for the data.

    As you can see in the code below, I use most of Kendra’s query to join these two tables together. First, we look for steps, so step_id != 0, and we look for failures. A status of 0 is a failure here, where 1 is success.

    Update: Changed the query after the comment and another bug I noticed.

    WITH cteActivity (job_id, start_execution_date)
    AS ( -- get the latest job execution for all jobs
        SELECT job_id,
               MAX(start_execution_date) AS start_execution_date
        FROM msdb.dbo.sysjobactivity
        GROUP BY job_id)
    , cteJobStep (Job_ID, Step_Name, run_date, run_time)
        AS (SELECT jh.job_id,
                   jh.step_name AS JobStepName,
                   jh.run_date,
                   jh.run_time
            FROM msdb.dbo.sysjobhistory jh
                INNER JOIN cteActivity ja
                    ON jh.job_id = ja.job_id
            WHERE jh.run_status = 0 --step failed
                  AND jh.step_id != 0
                  --         and jh.job_id = CONVERT(uniqueidentifier, '8C673935-F8C1-4E7D-94D3-1F3CAE50D7DC')
                  AND --this block ensures that we just pull information from the most recent job run
                (
                -- The start time of the step, converted to datetime
                CONVERT(DATETIME, RTRIM(jh.run_date))
                + (jh.run_time * 9 + jh.run_time % 10000 * 6 + jh.run_time % 100
                   * 10
                  ) / 216e4 >= ja.start_execution_date -- the time the job last started
                )

    Next, I kept most of Kendra’s query, but I commented out the line that limits this to a specific ID. I just want all step failures. I did keep the part that only checks the latest execution of the job.

    The outer query just counts these up and returns a number. This lets me know how many job steps have failed during their latest execution.

    This is a good first step, but this is something I could add in SQL Monitor as a custom metric or in any tool for alerting. When I have steps failing, I might want to know.

  • Daily Coping 18 Aug 2021

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag. 

    Today’s tip is to contact a friend to let them know you’re thinking of them.

    I actually had a friend reach out to me recently, just checking how I was doing. It was surprising to me, since I was actually thinking to reach out to them, but kept letting something get in the way. We had a nice text chat across a few minutes.

    I did reach out to another friend, telling them I was thinking about them and hoping I’d see them soon. This person made time for lunch, and we had a nice time catching up, something we’d not done in a few months.

    Make time for friends, at least a few.