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

Bala Narasimha Challa 466 Reputation points
2021-03-30T11:10:13.67+00:00

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.
12,607 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,546 questions
0 comments No comments
{count} votes

Accepted answer
  1. Guoxiong 8,126 Reputation points
    2021-03-30T19:23:39.49+00:00
    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];
    
    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful