• Here, I will even help you start. Here is a script to create working copies of the two msdb tables used in your query. All you need to do is add the appropriate INSERT statements to populate the tables with sample data.

    /****** Object: Table [dbo].[wrksysjobhistory] Script Date: 3/10/2013 1:19:43 PM ******/

    if object_id('dbo.wrksysjobhistory') is not null

    DROP TABLE [dbo].[wrksysjobhistory]

    GO

    /****** Object: Table [dbo].[wrksysjobhistory] Script Date: 3/10/2013 1:19:43 PM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[wrksysjobhistory](

    [instance_id] [int] IDENTITY(1,1) NOT NULL,

    [job_id] [uniqueidentifier] NOT NULL,

    [step_id] [int] NOT NULL,

    [step_name] [sysname] NOT NULL,

    [sql_message_id] [int] NOT NULL,

    [sql_severity] [int] NOT NULL,

    [message] [nvarchar](4000) NULL,

    [run_status] [int] NOT NULL,

    [run_date] [int] NOT NULL,

    [run_time] [int] NOT NULL,

    [run_duration] [int] NOT NULL,

    [operator_id_emailed] [int] NOT NULL,

    [operator_id_netsent] [int] NOT NULL,

    [operator_id_paged] [int] NOT NULL,

    [retries_attempted] [int] NOT NULL,

    [server] [sysname] NOT NULL

    )

    GO

    /****** Object: Table [dbo].[wrksysjobs] Script Date: 3/10/2013 1:19:57 PM ******/

    if object_id('dbo.wrksysjobs') is not null

    DROP TABLE [dbo].[wrksysjobs]

    GO

    /****** Object: Table [dbo].[wrksysjobs] Script Date: 3/10/2013 1:19:57 PM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[wrksysjobs](

    [job_id] [uniqueidentifier] NOT NULL,

    [originating_server_id] [int] NOT NULL,

    [name] [sysname] NOT NULL,

    [enabled] [tinyint] NOT NULL,

    [description] [nvarchar](512) NULL,

    [start_step_id] [int] NOT NULL,

    [category_id] [int] NOT NULL,

    [owner_sid] [varbinary](85) NOT NULL,

    [notify_level_eventlog] [int] NOT NULL,

    [notify_level_email] [int] NOT NULL,

    [notify_level_netsend] [int] NOT NULL,

    [notify_level_page] [int] NOT NULL,

    [notify_email_operator_id] [int] NOT NULL,

    [notify_netsend_operator_id] [int] NOT NULL,

    [notify_page_operator_id] [int] NOT NULL,

    [delete_level] [int] NOT NULL,

    [date_created] [datetime] NOT NULL,

    [date_modified] [datetime] NOT NULL,

    [version_number] [int] NOT NULL

    )

    GO

    SET ANSI_PADDING OFF

    GO