Get SQL jobs list along with SQL scripts which is used in job

asked 2021-03-30T11:10:13.67+00:00
balanarasimha c 466 Reputation points

HI Team,

Is their any option to get the SQL jobs list along with SQL scripts which is used in job.

Please help on same.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
8,467 questions
No comments
{count} votes

Accepted answer
  1. answered 2021-03-30T19:23:39.49+00:00
    Guoxiong 7,681 Reputation points
    USE [msdb];
    GO
    
    SELECT 
        j.[name] AS [Job Name], 
        s.[step_name] AS [Step_Name],
        s.[database_name] AS [Database Name],
        s.[command] AS [SQL Script]
    FROM [dbo].[sysjobs] AS j
    INNER JOIN [dbo].[sysjobsteps] AS s ON j.[job_id] = s.[job_id]
    WHERE j.[enabled] = 1
    AND s.[subsystem] = 'TSQL'
    ORDER BY j.[name], s.[step_id];
    
    No comments

0 additional answers

Sort by: Most helpful