forked from himadanreddy/SQL-DBA-SCRIPTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path090.sp_getRunningJobs.sql
More file actions
63 lines (61 loc) · 1.33 KB
/
090.sp_getRunningJobs.sql
File metadata and controls
63 lines (61 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
USE [DBAdmin]
GO
/****** Object: StoredProcedure [dbo].[pr_getRunningJobs] Script Date: 08/11/2011 17:37:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[pr_getRunningJobs]
@name Varchar(max) = null,
@Return int Output
as
/*
State Column
0 = Not idle or suspended,
1 = Executing,
2 = Waiting For Thread,
3 = Between Retries,
4 = Idle,
5 = Suspended,
6 = WaitingForStepToFinish,
7 = PerformingCompletionActions
*/
set nocount on
create table #enum_job (
Job_ID uniqueidentifier,
Last_Run_Date int,
Last_Run_Time int,
Next_Run_Date int,
Next_Run_Time int,
Next_Run_Schedule_ID int,
Requested_To_Run int,
Request_Source int,
Request_Source_ID varchar(100),
Running int,
Current_Step int,
Current_Retry_Attempt int,
[State] int
)
DECLARE @b binary(16)
--DECLARE @Return int
DECLARE @u uniqueidentifier
select @u = job_id from msdb.dbo.sysjobs where name = @name
SET @b = CONVERT(binary(16), @u)
--SELECT @b
--select @u
insert into #enum_job
exec master.dbo.xp_sqlagent_enum_jobs 1,sa, @b
if (select count (*) from #enum_job where running = 1) <> 0
begin
select @Return = [State] from #enum_job where running = 1
end
else
begin
set @Return = 0
end
--select * from #enum_job
--select @Return
drop table #enum_job
/*
DBAdmin..pr_getRunningJobs 'GROW: Process OLAP OASRPTP02A.OAS All'
*/