Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345»»»

Script to calculate when a job ended. Expand / Collapse
Author
Message
Posted Sunday, March 31, 2013 1:01 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, July 27, 2014 6:10 AM
Points: 4,179, Visits: 4,260
Lynn Pettis (3/10/2013)
Welsh Corgi (3/10/2013)
Lynn Pettis (3/10/2013)
Since some of us do not necessarily have a similar environment as you, it may be helpful if you created temporary tables and populated it with data from your msdb database for us to work with.

A little hard to work on your code with no data to test against. Won't know if what we did was what you are actually trying to accomplish.

From your own signature block:


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/



You know it is a system table why do I need to create a system table?

Thank you.






How about for the fact some of us don't necessarily have data in those tables? Most of my msdb database tables are empty, I have no scheduled jobs running, nor do I have any jobs that may even look like yours. My VM at work is the same, no jobs, no data. As for the production systems, on secure networks in theater so no access.

I also don't feel compelled to develop test data to help you do your work. I am more than happy to help, but give us something to work with.


You can't create a job and execute it so that you will have data to test?


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Post #1437317
Posted Sunday, March 31, 2013 1:06 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:45 PM
Points: 23,081, Visits: 31,620
Welsh Corgi (3/31/2013)
Lynn Pettis (3/10/2013)
Welsh Corgi (3/10/2013)
Lynn Pettis (3/10/2013)
Since some of us do not necessarily have a similar environment as you, it may be helpful if you created temporary tables and populated it with data from your msdb database for us to work with.

A little hard to work on your code with no data to test against. Won't know if what we did was what you are actually trying to accomplish.

From your own signature block:


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/



You know it is a system table why do I need to create a system table?

Thank you.






How about for the fact some of us don't necessarily have data in those tables? Most of my msdb database tables are empty, I have no scheduled jobs running, nor do I have any jobs that may even look like yours. My VM at work is the same, no jobs, no data. As for the production systems, on secure networks in theater so no access.

I also don't feel compelled to develop test data to help you do your work. I am more than happy to help, but give us something to work with.


You can't create a job and execute it so that you will have data to test?


Yes, I can. But all that is going to show me is what your query returns. What is it you WANT it to return? You need to show me that.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1437318
Posted Sunday, March 31, 2013 1:10 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, July 27, 2014 6:10 AM
Points: 4,179, Visits: 4,260
Lynn Pettis (3/31/2013)
Welsh Corgi (3/31/2013)
Lynn Pettis (3/10/2013)
Welsh Corgi (3/10/2013)
Lynn Pettis (3/10/2013)
Since some of us do not necessarily have a similar environment as you, it may be helpful if you created temporary tables and populated it with data from your msdb database for us to work with.

A little hard to work on your code with no data to test against. Won't know if what we did was what you are actually trying to accomplish.

From your own signature block:


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/



You know it is a system table why do I need to create a system table?

Thank you.






How about for the fact some of us don't necessarily have data in those tables? Most of my msdb database tables are empty, I have no scheduled jobs running, nor do I have any jobs that may even look like yours. My VM at work is the same, no jobs, no data. As for the production systems, on secure networks in theater so no access.

I also don't feel compelled to develop test data to help you do your work. I am more than happy to help, but give us something to work with.


You can't create a job and execute it so that you will have data to test?


Yes, I can. But all that is going to show me is what your query returns. What is it you WANT it to return? You need to show me that.


I want the following colums displayed in a valid date format:

This is what I get:

last_run_date last_Run_Time
20130331 101254

I want the last_run_date and last_run_date & last_end_Date formated as follows:


2013-03-31 03:25:00.000 2013-03-31 03:37:33.000

If you refer to the code for the sysjobs it has the logice and the expected output.

I can't get it to work for the sysjobstep.


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Post #1437320
Posted Sunday, March 31, 2013 1:28 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:45 PM
Points: 23,081, Visits: 31,620
Perhaps something more like this:


SELECT
j.job_id,
s.srvname,
j.name,
js.step_id,
js.command,
j.enabled ,
js.last_run_date,
js.last_Run_Time,
js.last_run_duration,
msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time) AS Run_Datetime,
dateadd(second, ((js.last_run_duration / 10000) * 3600) + (((js.last_run_duration / 100) % 60) * 60) + (js.last_run_duration % 60), msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time)) as EndRunDate
FROM
dbo.sysjobs j
JOIN dbo.sysjobsteps js
ON js.job_id = j.job_id
JOIN master.dbo.sysservers s
ON s.srvid = j.originating_server_id
WHERE
j.name = 'TestJob';





Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1437321
Posted Sunday, March 31, 2013 1:33 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, July 27, 2014 6:10 AM
Points: 4,179, Visits: 4,260
Lynn Pettis (3/31/2013)
Perhaps something more like this:


SELECT
j.job_id,
s.srvname,
j.name,
js.step_id,
js.command,
j.enabled ,
js.last_run_date,
js.last_Run_Time,
js.last_run_duration,
msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time) AS Run_Datetime,
dateadd(second, ((js.last_run_duration / 10000) * 3600) + (((js.last_run_duration / 100) % 60) * 60) + (js.last_run_duration % 60), msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time)) as EndRunDate
FROM
dbo.sysjobs j
JOIN dbo.sysjobsteps js
ON js.job_id = j.job_id
JOIN master.dbo.sysservers s
ON s.srvid = j.originating_server_id
WHERE
j.name = 'TestJob';




If you execute the code you will get the following error:


Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.


Thanks for you reply.


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Post #1437322
Posted Sunday, March 31, 2013 1:37 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:45 PM
Points: 23,081, Visits: 31,620
Welsh Corgi (3/31/2013)
Lynn Pettis (3/31/2013)
Perhaps something more like this:


SELECT
j.job_id,
s.srvname,
j.name,
js.step_id,
js.command,
j.enabled ,
js.last_run_date,
js.last_Run_Time,
js.last_run_duration,
msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time) AS Run_Datetime,
dateadd(second, ((js.last_run_duration / 10000) * 3600) + (((js.last_run_duration / 100) % 60) * 60) + (js.last_run_duration % 60), msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time)) as EndRunDate
FROM
dbo.sysjobs j
JOIN dbo.sysjobsteps js
ON js.job_id = j.job_id
JOIN master.dbo.sysservers s
ON s.srvid = j.originating_server_id
WHERE
j.name = 'TestJob';




If you execute the code you will get the following error:


Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.


Thanks for you reply.


Runs just fine on my system. Perhaps now is the time you should consider my original advise and create a mirror of your system tables, insert some of your data and let us try against what you are running against.




Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1437324
Posted Sunday, March 31, 2013 1:39 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:45 PM
Points: 23,081, Visits: 31,620
I just did a copy/paste/execute of the code I posted in a new SSMS query window, no problems.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1437325
Posted Sunday, March 31, 2013 1:45 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, July 27, 2014 6:10 AM
Points: 4,179, Visits: 4,260
Welsh Corgi (3/31/2013)
Lynn Pettis (3/31/2013)
Perhaps something more like this:


SELECT
j.job_id,
s.srvname,
j.name,
js.step_id,
js.command,
j.enabled ,
js.last_run_date,
js.last_Run_Time,
js.last_run_duration,
msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time) AS Run_Datetime,
dateadd(second, ((js.last_run_duration / 10000) * 3600) + (((js.last_run_duration / 100) % 60) * 60) + (js.last_run_duration % 60), msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time)) as EndRunDate
FROM
dbo.sysjobs j
JOIN dbo.sysjobsteps js
ON js.job_id = j.job_id
JOIN master.dbo.sysservers s
ON s.srvid = j.originating_server_id
WHERE
j.name = 'TestJob';




If you execute the code you will get the following error:


Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.


Thanks for you reply.



What job did you create?

What was in the execute of the step(s)?


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Post #1437326
Posted Sunday, March 31, 2013 1:50 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:45 PM
Points: 23,081, Visits: 31,620
Welsh Corgi (3/31/2013)
Welsh Corgi (3/31/2013)
Lynn Pettis (3/31/2013)
Perhaps something more like this:


SELECT
j.job_id,
s.srvname,
j.name,
js.step_id,
js.command,
j.enabled ,
js.last_run_date,
js.last_Run_Time,
js.last_run_duration,
msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time) AS Run_Datetime,
dateadd(second, ((js.last_run_duration / 10000) * 3600) + (((js.last_run_duration / 100) % 60) * 60) + (js.last_run_duration % 60), msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time)) as EndRunDate
FROM
dbo.sysjobs j
JOIN dbo.sysjobsteps js
ON js.job_id = j.job_id
JOIN master.dbo.sysservers s
ON s.srvid = j.originating_server_id
WHERE
j.name = 'TestJob';




If you execute the code you will get the following error:


Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.


Thanks for you reply.



What job did you create?

What was in the execute of the step(s)?


You can't answer my questions or provide the information I request and you expect me to answer yours?

It doesn't matter what job I created or what I did in the job step(s). The job ran and put data in the tables that when accessed by your query with my added code to compute the End Date ran without problems.

This means there is more going on on your system and that we need to see some data from you in order to help answer your questions. I am more than willing to help, but you really need to help in that regard.




Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1437327
Posted Sunday, March 31, 2013 1:56 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, July 27, 2014 6:10 AM
Points: 4,179, Visits: 4,260
Lynn Pettis (3/31/2013)
Welsh Corgi (3/31/2013)
Welsh Corgi (3/31/2013)
Lynn Pettis (3/31/2013)
Perhaps something more like this:


SELECT
j.job_id,
s.srvname,
j.name,
js.step_id,
js.command,
j.enabled ,
js.last_run_date,
js.last_Run_Time,
js.last_run_duration,
msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time) AS Run_Datetime,
dateadd(second, ((js.last_run_duration / 10000) * 3600) + (((js.last_run_duration / 100) % 60) * 60) + (js.last_run_duration % 60), msdb.dbo.Agent_datetime(js.last_Run_Date, js.last_Run_Time)) as EndRunDate
FROM
dbo.sysjobs j
JOIN dbo.sysjobsteps js
ON js.job_id = j.job_id
JOIN master.dbo.sysservers s
ON s.srvid = j.originating_server_id
WHERE
j.name = 'TestJob';




If you execute the code you will get the following error:


Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.


Thanks for you reply.



What job did you create?

What was in the execute of the step(s)?


You can't answer my questions or provide the information I request and you expect me to answer yours?

It doesn't matter what job I created or what I did in the job step(s). The job ran and put data in the tables that when accessed by your query with my added code to compute the End Date ran without problems.

This means there is more going on on your system and that we need to see some data from you in order to help answer your questions. I am more than willing to help, but you really need to help in that regard.



I asked you for that information so that I could replicate what you did .

Disregard my post

Thank you.


For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Post #1437328
« Prev Topic | Next Topic »

Add to briefcase «««12345»»»

Permissions Expand / Collapse