A Simple TSQL To Find The Last N RUN Status Of The SQL Jobs / Job History

Feb 22, 2008

Replace the <<job name>> with the actual job name
---Last n RUN status of the job------


SELECT TOP 20

SJ.name 'JOB Name'

,'Run date : ' +

REPLACE(CONVERT(varchar,convert(datetime,convert(varchar,run_date)),102),'.','-')+' '+

SUBSTRING(RIGHT('000000'+CONVERT(varchar,run_time),6),1,2)+':'+SUBSTRING(RIGHT('000000'+CONVERT(varchar,run_time),6),3,2)+':'+SUBSTRING(RIGHT('000000'+CONVERT(varchar,run_time),6),5,2) 'Start Date Time'

,SUBSTRING(RIGHT('000000'+CONVERT(varchar,run_duration),6),1,2)+':'+SUBSTRING(RIGHT('000000'+CONVERT(varchar,run_duration),6),3,2)+':'+SUBSTRING(RIGHT('000000'+CONVERT(varchar,run_duration),6),5,2) 'Duration'

,CASE run_status WHEN 1 THEN '1-SUCCESS' WHEN 0 THEN '0-FAILED' ELSE CONVERT(varchar,run_status) END AS 'Status'
,Step_id

,[Message]

,[Server]

FROM MSDB..SysJobHistory SJH

RIGHT JOIN MSDB..SysJobs SJ

ON SJ.Job_Id = SJH.job_id

WHERE SJ.name LIKE '%<<job name>>%'

AND Step_ID = 0 --Comments this line if you want to see the status of each step of the job

ORDER BY run_date DESC, run_time DESC, step_ID DESC

---Last n RUN status of the job---------

View 7 Replies


ADVERTISEMENT

Scheduled Jobs: History Info Disappears

Jul 13, 2001

From time to time, history info on our scheduled jobs (SQL Server 7.0) is missing. When I try to view job history, I get a popup saying "There is no history information for this job". Sometimes the job does run, however, sometimes it doesn't... The problem seems to happen randomly on random scheduled jobs. Any tips on how to get back the consistency of info we used to enjoy in 6.5?

Also, is there a way to specify how many job runs the history should display. It only goes as far as 5 or so, I wonder if it can capture more "runs"?

Please email back the answer to lpinskaya@firstam.com - it would be GREATLY appreciated.

View 2 Replies View Related

How To Use TSQL To Monitor Replication Status

Dec 7, 2006

To monitor the status of replication in SQL 2000 we insert the resuts of sp_MShelp_replication_status into a temp table and review the status. In SQL 2005 this stored procedure has changed and now does it's own insert into execute command. Since insert execute commands can not be nested we must find another way to programically monitor replication using TSQL. We could call sys.sp_replmonitorhelppublisherhelper but we can't seem to find it in the distribution database. It must be hidden somehow. Any ideas?

Thanks,

Danny

View 6 Replies View Related

SQL 2012 :: Retrieve Job History For All The Jobs Using Central Management Server?

Apr 2, 2015

Is there anyway we could retrieve the job history for all the jobs in all the sql server using Central Management Server?

View 0 Replies View Related

Status Field In Management - Jobs

Apr 20, 2007

I am trying get the status field from the list of jobs in management. I have a activex script that queries system tables to find out if a job has failed and sends the report via e-mail.

Currently I use this query to get the names of jobs failed...
SELECT
name
FROM msdb.dbo.sysjobs A, msdb.dbo.sysjobservers B WHERE A.job_id = B.job_id AND B.last_run_outcome = 0
ORDER BY name

I need to add some criteria around the status field to get the appropriate results.

anybody?
Cheers :beer:

View 1 Replies View Related

Checking Jobs Status Through Query

Oct 27, 2006

I am a Junior DBA and i have to checks the various jobs on different servers.Please help me with a T-SQL way by which i can check the Job status through a Query.



Thanks in Advance

Jacx

View 3 Replies View Related

Fetching Jobs Last Run Status Using Bat File?

Aug 12, 2015

I wrote a bat file to start a sql job using dos command

osql -S “[SQL SERVER NAME]” -E -Q”exec msdb.dbo.sp_start_job ‘[SQL JOB NAME]'”

[URL]

now this bat file only start the job, does not wait for it completion or send us the success or failure message.Now i want to check the value of LastRunStatus for this job using BAT file?? Is is possible to fetch the LastRunStatus of sql job using bat file.However i have achieved the same using vbscript that starts a job using vbscript start method and then looping through al the jobs at server and displaying the LastRunStatus. However i wanted to achieve this uisng bat file only.

View 3 Replies View Related

Disable Jobs With TSQL

Dec 9, 2005

Does anyone know how to disable and re-enable jobs using tsql?

View 1 Replies View Related

DB Engine :: Agent Jobs Status For Multiple Servers Using Powershell?

Oct 14, 2014

I am following website link:

[URL]

I require to gather status details about all the SQL Agent jobs in the environment on multiple SQL Servers.

I tried to edit the script using:

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO")
$sqlServerName = 'localhostdeveloper'
 $sqlServer = New-Object Microsoft.SqlServer.Management.Smo.Server($sqlServerName)
 foreach($job in $sqlServer.JobServer.Jobs)
{
$job | select Name, OwnerLoginName, IsEnabled, LastRunDate, LastRunOutcome, DateCReated, DateLastModified
}

but SQL Agent jobs are not reflecting in the mail output...

View 11 Replies View Related

Newbie In Tsql - Finding Latest Failed Jobs

Mar 16, 2008

I am a newbie to tsql. I am trying to find if a job has failed, if so I only want to pickup the lastest job. I want to see name,message and run date. I know I need to find the max run_date and run_time for each job_id. I know that I need to join the sysjobhistory table and the sysjobs tables. I also know that I need status not equal to one. I have tried thousands of different things and nothing seems to work. If I ever get this to work then I only want to look at jobs in the last 24 hours. I am not going to include any of my job since I have tried so many things and I have been all over the map.

View 8 Replies View Related

SQLAgent - TSQL Jobs Hangs (SQL Server 2005)

Aug 15, 2007



I have two tables
t_DTM_DATA_STAGING around 2 million records
t_DTM_DATA around 251 million records

The below SQL statement looks for records in the t_DTM_DATA_STAGING table that are not in the t_DTM_DATA table and adds them to a 3rd table. (t_DTM_DATA_STAGING2)

This statement has been running fine for weeks, but now it seems to get hung every day. I ran sp_Who2 and it says the status is runnable. I let it run for around 5 or 6 hours the other day to see if it will finish but it didn't. This SQL job is step 3 in a 6 step SQLAgent job that usually finishes in 30 to 45 minutes.

I'm not sure how to troubleshoot this problem. No other jobs are running at the time this job runs.

Could this SQL statement be written a better way?

Thanks for any help anyone can provide.

Jerid

SET QUOTED_IDENTIFIER ON

INSERT INTO
[DTM].[dbo].[t_DTM_DATA_STAGING2]
([CP],,[MAJ],[MINR],[LOCN],[DPT],[YEAR],[PD],[WK],[TRDT],[SYSTEM],[AMOUNT],[DESCRIPTION],[GROUP],[VENDOR]
,[INVOICE],[IDAT],[PO_NUMBER],[DDAT],[RCV#],[RDAT],[RSP],[EXPLANATION],[UPLOAD_DATE],[UPLOAD_USER],[UPLOAD_NAME]
,[RELEASE_DATE],[RELEASE_USER],[RELEASE_NAME],[TRTM])
SELECT
t_DTM_DATA_STAGING.CP, t_DTM_DATA_STAGING.CO, t_DTM_DATA_STAGING.MAJ, t_DTM_DATA_STAGING.MINR, t_DTM_DATA_STAGING.LOCN, t_DTM_DATA_STAGING.DPT,
t_DTM_DATA_STAGING.YEAR, t_DTM_DATA_STAGING.PD, t_DTM_DATA_STAGING.WK, t_DTM_DATA_STAGING.TRDT, t_DTM_DATA_STAGING.SYSTEM, t_DTM_DATA_STAGING.AMOUNT,
t_DTM_DATA_STAGING.DESCRIPTION, t_DTM_DATA_STAGING.[GROUP], t_DTM_DATA_STAGING.VENDOR, t_DTM_DATA_STAGING.INVOICE, t_DTM_DATA_STAGING.IDAT,
t_DTM_DATA_STAGING.PO_NUMBER, t_DTM_DATA_STAGING.DDAT, t_DTM_DATA_STAGING.RCV#, t_DTM_DATA_STAGING.RDAT, t_DTM_DATA_STAGING.RSP,
t_DTM_DATA_STAGING.EXPLANATION, t_DTM_DATA_STAGING.UPLOAD_DATE, t_DTM_DATA_STAGING.UPLOAD_USER, t_DTM_DATA_STAGING.UPLOAD_NAME,
t_DTM_DATA_STAGING.RELEASE_DATE, t_DTM_DATA_STAGING.RELEASE_USER, t_DTM_DATA_STAGING.RELEASE_NAME, t_DTM_DATA_STAGING.TRTM
FROM
t_DTM_DATA_STAGING
LEFT OUTER JOIN
t_DTM_DATA AS t_DTM_DATA_1
ON
t_DTM_DATA_STAGING.TRTM = t_DTM_DATA_1.TRTM
AND
t_DTM_DATA_STAGING.TRDT = t_DTM_DATA_1.TRDT
AND
t_DTM_DATA_STAGING.PD = t_DTM_DATA_1.PD
AND
t_DTM_DATA_STAGING.YEAR = t_DTM_DATA_1.YEAR
AND
t_DTM_DATA_STAGING.DPT = t_DTM_DATA_1.DPT
AND
t_DTM_DATA_STAGING.LOCN = t_DTM_DATA_1.LOCN
AND
t_DTM_DATA_STAGING.MINR = t_DTM_DATA_1.MINR
AND
t_DTM_DATA_STAGING.MAJ = t_DTM_DATA_1.MAJ
AND
t_DTM_DATA_STAGING.CO = t_DTM_DATA_1.CO
AND
t_DTM_DATA_STAGING.CP = t_DTM_DATA_1.CP
WHERE
(t_DTM_DATA_1.CP IS NULL)

View 4 Replies View Related

SQL 2012 :: How To Find CPU Usage From History

Jun 15, 2015

I am trying to find out CPU utilization from the history using process.%processor time. I am having dual core CPU with 2 numa nodes each having 16 logical cpus bind to it.

how to calculate the CPU utilization using perfmon.I tried to use SQL query which gives CPU history using SQL DMV, but I am unable to get the exact value. Because in between I have used the same querry to capture my CPU usage on the run day, the value on run day and the query which iam tryting to pull out is different. I am using the same query to pull the history data with providing the date.

-- Get CPU Utilization History (SQL Server 2008 and above)

DECLARE @ts BIGINT
SELECT @ts =(SELECT cpu_ticks/(cpu_ticks/ms_ticks)
FROM sys.dm_os_sys_info);
SELECT SQLProcessUtilization AS [SQLServer_Process_CPU_Utilization],
SystemIdle AS [System_Idle_Process],
100 - SystemIdle - SQLProcessUtilization AS [Other_Process_CPU_Utilization],

[code]....

View 1 Replies View Related

SQL Server 2005 Start Jobs Window And Job Activity Monitor Do Not Show Job Status Correcly

Mar 14, 2007

Hi,

We have development and user acceptance (UA) servers. When I start a job on the development server, on the management studio, Start Jobs window and Job activity windows indicate "Executing" until the end of the job and finish with "success" or "failure"

But on the UA server, second after I start a job, Start Jobs window comes up with "success" or failure" and Job activity monitor says "idle" but Job continues to log without any error message and updates the tables. So these two windows are not reliable at all. I have to add that I have only job operator rights on the UA server.

Does anybody know what the reason is ?

Thanks

View 5 Replies View Related

Analysis :: Where To Find Backup History Of Cube

Aug 7, 2015

Where to find history of cube backup? I am new to analysis services.

View 4 Replies View Related

How To Find Status Of SQL Job - Please Help

Sep 9, 2007

T-SQL for checking which jobs are currently running ?
And
what happen if index rebuild job overlap with shrink log file job
Is database wont allow to insert or update for other application


Thanks in Advance


Dina Satam

View 1 Replies View Related

SQL Server 2008 :: How To Find History Of Blocking Batch / Query

Mar 4, 2015

I see some time email say blocking took place and but it get resolved itself. how to find the history of batch/query which blocked another SPID?

View 3 Replies View Related

Insert / Update In Master Table And Also Save A History Of Changed Records : Using Data Flow/simple Sql Queries

Feb 9, 2007

Hi,

My scenario:

I have a master securities table which has 7 fields. As a part of the daily process I am uploading flat files into database tables. The flat files contains the master(static) security data as well as the analytics(transaction) data. I need to

1) separate the master (static) data from the flat files,

2) check whether that data is present in the master table, if not then insert that data into the master table

3) If data present then move that existing record to an history table and then update the main master table.

All the 7 fields need to be checked to uniquely identify a single record in the master table.

How can this be done? Whether we can us a combination of data flow items or write a sql procedure to do all this.

Thanks in advance for your help.

Regards,

$wapnil

View 4 Replies View Related

Need To Find All Jobs Using Sa Pwd In It.

Mar 15, 2007

I need to know if there is any way to extract all our jobs/dts packages
where the 'sa' password is being used in either the job steps or any stored proc the sa pwd harcoded in it.

View 3 Replies View Related

Execution Time Gap Between Simple Tsql And Stored Procedure In SQl Server 2005

Oct 16, 2007

Hi ,

I ma using sql server 2005.I have a bunch of statements of sql and i have created a stored procedure for those. When i execute i found that there is lot's of difference between execution time of stored procedure and direct sql in query windows.

can anyone help me to optimize the execution time for stored prcedure even stored prcedure is very simple.
I have used sql server 2000 and i am new in sql server 2005.

View 1 Replies View Related

Simple Question; Is There A Way To Geneteate A List Of Databases, Jobs, DTS Packages

Jul 5, 2006

I need to generate a list of databases, jobs, DTS packages, Linked servers, and users.
Is there a simple script or procedure for this?

Thanks

View 2 Replies View Related

CURSOR_STATUS Unreliable: SQL 2005 -- Is There A Better Way To Find Cursor Status?

May 27, 2008

What is the best way of reliably closing a cursor inside a BEGIN CATCH block? The simple problem statement is: I want to check if the cursor is open, then close it. I'm trying to use CURSOR_STATUS function and it seems to return a -3 (both when the cursor is open and not open.). Is this a bug or am I missing something?

I have removed all of my code and only provided what is necessary to repro the problem.

====================================================================================================

CREATE PROCEDURE dbo.repro_PROC

(

@condition1 varchar(10),

@condition2 varchar(10)

)

AS

BEGIN

BEGIN TRY


SET NOCOUNT ON;

SET XACT_ABORT ON;

DECLARE @dbName varchar(64), @dbid int;

DECLARE @FileID int;

DECLARE @Physical_Name varchar(512);

IF (@condition1 = 'ERROR')


RAISERROR ('ERROR: This error happens before any cursor is declared or is open', 16, 1);


DECLARE dbNameCursor CURSOR FOR SELECT Name, database_id FROM master.sys.databases ORDER BY Name;

OPEN dbNameCursor;


FETCH NEXT FROM dbNameCursor INTO @dbName, @dbid;

WHILE @@FETCH_STATUS = 0

BEGIN


DECLARE fileCursor CURSOR FOR SELECT File_ID, Physical_Name FROM master.sys.master_files

WHERE database_id = @dbid

ORDER BY File_ID;


OPEN fileCursor;

FETCH NEXT FROM fileCursor INTO @FileID, @Physical_Name;

WHILE @@FETCH_STATUS = 0

BEGIN


-- some condition which causes an exception

IF (@condition2 = 'ERROR')


RAISERROR ('ERROR: This error happens after both cursors are open', 16, 1);


FETCH NEXT FROM fileCursor INTO @FileID, @Physical_Name;

END

CLOSE fileCursor;

DEALLOCATE fileCursor;




FETCH NEXT FROM dbNameCursor INTO @dbName, @dbid;

END

CLOSE dbNameCursor;

DEALLOCATE dbNameCursor;

END TRY

BEGIN CATCH


DECLARE @ErrorMessage NVARCHAR(4000);

DECLARE @ErrorSeverity INT;

DECLARE @ErrorState INT;

DECLARE @fileCursorStatus INT;

DECLARE @dbNameCursorStatus INT;


SELECT

@ErrorMessage = ERROR_MESSAGE(),

@ErrorSeverity = ERROR_SEVERITY(),

@ErrorState = ERROR_STATE();


SET @fileCursorStatus = CURSOR_STATUS('local', 'fileCursor');

SET @dbNameCursorStatus = CURSOR_STATUS('local', 'dbNameCursor');

PRINT 'Cursor_Status (fileCursor) = ' + convert(varchar, @fileCursorStatus);

PRINT 'Cursor_Status (dbNameCursor) = ' + convert(varchar, @dbNameCursorStatus);


IF (@fileCursorStatus >= 0)

BEGIN


PRINT 'Closing fileCursor';

CLOSE fileCursor;

DEALLOCATE fileCursor;

END


IF (@dbNameCursorStatus >= 0)

BEGIN


PRINT 'Closing dbNameCursor';

CLOSE dbNameCursor;

DEALLOCATE dbNameCursor;

END


-- info about the original error

RAISERROR (@ErrorMessage, -- Message text.

@ErrorSeverity, -- Severity.

@ErrorState -- State.

);


END CATCH;

END;

====================================================================================================

EXEC dbo.repro_PROC @condition1='ERROR', @condition2='NO-ERROR'


Output:

Cursor_Status (fileCursor) = -3

Cursor_Status (dbNameCursor) = -3

Msg 50000, Level 16, State 1, Procedure repro_PROC, Line 88

ERROR: This error happens before any cursor is declared or is open

-------------------------------------------------------------------------

EXEC dbo.repro_PROC @condition1='NO-ERROR', @condition2='ERROR'


Output:

Cursor_Status (fileCursor) = -3

Cursor_Status (dbNameCursor) = -3

Msg 50000, Level 16, State 1, Procedure repro_PROC, Line 89

ERROR: This error happens after both cursors are open

-------------------------------------------------------------------------

EXEC dbo.repro_PROC @condition1='NO-ERROR', @condition2='ERROR'


Output:

Cursor_Status (fileCursor) = -3

Cursor_Status (dbNameCursor) = -3

Msg 50000, Level 16, State 1, Procedure repro_PROC, Line 89

A cursor with the name 'dbNameCursor' already exists. <=== THIS IS A PROBLEM

=================================================================================================


If I try to close the cursor when the status = -3, then sometimes it closes successfully, some other times, it errors "Cursor NOT open" etc.

View 6 Replies View Related

Tsql To Find Out If Ssis Package Is Running ?

Mar 12, 2008

what table/column can we query to determine if ssis package is running ?
How do we kill package that is running ?

View 4 Replies View Related

Query To Find Who Runs Jobs

Aug 29, 2007

I would like to create a query to find what user owns the job. It probably is in the master db, but I wouldn't know where to begin other than that. Telling me how to either change the job owner or create a job through t-sql would also help. Thanks
-Kyle

View 1 Replies View Related

MSSQL: Find What Jobs Had To Start During Server Was Down

Apr 11, 2007

Hi,
This is the situation:
There are around 300 jobs on the server. The server shutsdown abnormally and is not functional for let's say 2 hours. After the server is back on, I need to find what jobs had to start during the server was down.
Is there a way to get this list? I tried to write an SQL script that tells me the needed information, but the job schedule sheme is so complex that it would take too much time in developing such SQL script. Maybe anybody has a better solution, or has already made a similar script?
ThankYou.

View 2 Replies View Related

Transact SQL :: Find How Many Jobs Running In Parallel Between Interval

Oct 8, 2015

I try to find out how many jobs where run in parallel on my server in an interval of time. For example: between 1:00 AM and 2:00 AM there were MAX 66 jobs that run in parallel and MIN 4 jobs. I am not sure if I can find this info out from a system view or I need to play with sysjobhistory view.

View 10 Replies View Related

Query Find A List Of All The Jobs In A SQL 2005 Database

Apr 22, 2008



Hi,

I was wondering if there was a SQL query I could run that would list all the current jobs in a SQL 2005 database? I would like to check to ensure a job exists before I call it, but was having trouble finding a way to determine if it existed.

Thanks for any advice!

-Flea#

View 3 Replies View Related

How To Find Differences In Column Data Types Between Tables In Two Different Databases Using TSQL

Apr 21, 2008


I have Two Database that exist on Two seperate servers. The two database contain same schema and contains tables and columns of same name. Some tables have slight differences in terms of data types or Data type lenght.

For example if a Table on ServerA has a column named - CustomerSale with Varchar (100, Null) and a table on ServerB has a column named CustomerSale with Varchar (60, Null), how can i find if other columns have similar differences in all tables with the same name and columns in the two servers.

I am using SQL Server 2005. And the Two Servers are Linked Servers

What Script can i use to accomplish this task. Thanks






View 4 Replies View Related

SQL Server 2008 :: How To Find All Agent Jobs That Are Currently Running By Query

May 29, 2013

When I give job Id in filter of this query this will give job status of "Success" but actually my job is currently in executing stage. I want to get all jobs that are currently in executing status.

Use msdb
go
select distinct j.Name as "Job Name", --j.job_id,
case j.enabled
when 1 then 'Enable'
when 0 then 'Disable'

[Code] ....

View 4 Replies View Related

How To Find A Simple Quote In A Row

Mar 7, 2005

Hi,
I have a table with a "description" row.
In this row I may have some simple quote (') character.
How can I select them ?

something like :
select * from myTable where description like %'%

thanks

View 3 Replies View Related

Simple Question, But Can't Find What I Need!

Mar 15, 2007

Help. Several people have told me to connect to SSIS from SSMS, but I don't know how. Can someone PLEASE tell me how to connect to SQL Server Integration Services from Management Studio?

Thank you

View 2 Replies View Related

Does Anyone Know Where To Find A Simple Sample Code That Uses Asp.net 2.0 And SQL 2000 To ....

Nov 28, 2006

Does anyone know where to find a simple sample showing you how to use asp.net 2.0 with the login control to direct you to another aspx page using SQL 2000 as the database on a hosted server? I have been beating my head against the wall trying to figure this out and would be very appreciative if anyone knows a place out there that shows this?  I can find many sites that show you how to do this with SQL 2005, but not SQL 2000.  Thanks -  Chris 

View 4 Replies View Related

Equivalent Tsql For Sql Server 2000 Is Needed [from Sql Server 2005 Only Tsql]

Nov 19, 2007

Can anyone please give me the equivalent tsql for sql server 2000 for the following two queries which works fine in sql server 2005

1
-- Full Table Structure

select t.object_id, t.name as 'tablename', c.name as 'columnname', y.name as 'typename', case y.namewhen 'varchar' then convert(varchar, c.max_length)when 'decimal' then convert(varchar, c.precision) + ', ' + convert(varchar, c.scale)else ''end attrib,y.*from sys.tables t, sys.columns c, sys.types ywhere t.object_id = c.object_idand t.name not in ('sysdiagrams')and c.system_type_id = y.system_type_idand c.system_type_id = y.user_type_idorder by t.name, c.column_id


2
-- PK and Index
select t.name as 'tablename', i.name as 'indexname', c.name as 'columnname' , i.is_unique, i.is_primary_key, ic.is_descending_keyfrom sys.indexes i, sys.tables t, sys.index_columns ic, sys.columns cwhere t.object_id = i.object_idand t.object_id = ic.object_idand t.object_id = c.object_idand i.index_id = ic.index_idand c.column_id = ic.column_idand t.name not in ('sysdiagrams')order by t.name, i.index_id, ic.index_column_id

This sql is extracting some sort of the information about the structure of the sql server database[2005]
I need a sql whihc will return the same result for sql server 2000

View 1 Replies View Related

Simple Simple Linking Tables & Perform Calculation

Mar 22, 2007

found it

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved