Bells are ringing and everyone is singing,
It's Christmas! It's Christmas!
Wishing you a Merry Christmas and a Happy New Year.
Saturday, December 24, 2011
Merry Christmas !!!
Wednesday, December 7, 2011
How to Give Read Definition Permissio...
How to Give Read Definition Permission to a User for all Procedures and Functions http://ping.fm/ANAM6
Tuesday, December 6, 2011
SQL Server 2012 Editions Licensing Co...
SQL Server 2012 Editions Licensing Costing - SQL Server Licensing is depends on which edition your are buying and un... http://ping.fm/xgmV1
Wednesday, November 30, 2011
Install SQL Server 2008 R2 ?Step by S...
Install SQL Server 2008 R2 –Step by Step with Screenshots - Step-by-Step procedure for installing a new instance of ... http://ping.fm/jY6Ym
Wednesday, November 16, 2011
SQL Script to find Current Running Jobs and elapsed time
I do get a call from developers to check weather a any job is running on the server or not ? Mostly on Sunday morning they want to check that all data import / exports jobs finishes on time. So they wanted me to know what all the jobs are currently executing.
We can find the execution status from the Job Activity Monitor but we don't get the duration of execution in it. we can use the below query to find out the same. The Query fetches the Running jobs and calculates the time for which they are executing.
SQL Script to find current Running Jobs
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
)
INSERT INTO
#enum_job EXEC master.dbo.xp_sqlagent_enum_jobs 1, garbage
SELECT
R.name ,
R.last_run_date,
R.RunningForTime,
GETDATE()AS now
FROM
#enum_job a
INNER JOIN
(
SELECT
j.name,
J.JOB_ID,
ja.run_requested_date AS last_run_date,
(DATEDIFF(mi,ja.run_requested_date,GETDATE())) AS RunningFor,
CASE LEN(CONVERT(VARCHAR(5),DATEDIFF(MI,JA.RUN_REQUESTED_DATE,GETDATE())/60))
WHEN 1 THEN '0' + CONVERT(VARCHAR(5),DATEDIFF(mi,ja.run_requested_date,GETDATE())/60)
ELSE CONVERT(VARCHAR(5),DATEDIFF(mi,ja.run_requested_date,GETDATE())/60)
END
+ ':' +
CASE LEN(CONVERT(VARCHAR(5),(DATEDIFF(MI,JA.RUN_REQUESTED_DATE,GETDATE())%60)))
WHEN 1 THEN '0'+CONVERT(VARCHAR(5),(DATEDIFF(mi,ja.run_requested_date,GETDATE())%60))
ELSE CONVERT(VARCHAR(5),(DATEDIFF(mi,ja.run_requested_date,GETDATE())%60))
END
+ ':' +
CASE LEN(CONVERT(VARCHAR(5),(DATEDIFF(SS,JA.RUN_REQUESTED_DATE,GETDATE())%60)))
WHEN 1 THEN '0'+CONVERT(VARCHAR(5),(DATEDIFF(ss,ja.run_requested_date,GETDATE())%60))
ELSE CONVERT(VARCHAR(5),(DATEDIFF(ss,ja.run_requested_date,GETDATE())%60))
END AS RunningForTime
FROM
msdb.dbo.sysjobactivity AS ja
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS jh
ON
ja.job_history_id = jh.instance_id
INNER JOIN msdb.dbo.sysjobs_view AS j
ON
ja.job_id = j.job_id
WHERE
(
ja.session_id =
(
SELECT
MAX(session_id) AS EXPR1
FROM
msdb.dbo.sysjobactivity
)
)
)
R ON R.job_id = a.Job_Id
AND a.Running = 1
DROP TABLE #enum_job
Script OUTPUT
Thursday, October 27, 2011
Fireside Chat with SQL Server Enginee...
Fireside Chat with SQL Server Engineers After 24 Hours of PASS – Thurs, Sept 8, 2011 http://ping.fm/6t204
Thursday, October 13, 2011
SQL Server 2012 - SQL Server 2012 Th...
SQL Server 2012 - SQL Server 2012 Thank you for being part of our SQL Server community and all of your support as w... http://ping.fm/sHK6X
Subscribe to:
Posts (Atom)