question

balanarasimhac-1495 avatar image
0 Votes"
balanarasimhac-1495 asked MelissaMa-msft edited

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

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-generalsql-server-transact-sql
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

GuoxiongYuan-7218 avatar image
0 Votes"
GuoxiongYuan-7218 answered
 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];
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.