How to add a before and after timestamp to a sql job?

  • We have SQL Server 2000. I would like to add a timestamp before and after a job step. I was thinking of something like the following (I would need to add the seconds and miliseconds to the date statements):

    In the Job Step Command Box:

    SELECT 'StartTime is: '+ CONVERT(char(30), CURRENT_TIMESTAMP)

    GO

    DBCC DBREINDEX (TableA,'', 70)

    GO

    DBCC DBREINDEX (TableB,'', 70)

    GO

    DBCC DBREINDEX (TableC,'', 70)

    GO

    SELECT 'EndTime is: '+ CONVERT(char(30), CURRENT_TIMESTAMP)

    GO

    SELECT GETDATE() AS StartTime

    GO

    DBCC DBREINDEX (TableA,'', 70)

    GO

    DBCC DBREINDEX (TableB,'', 70)

    GO

    DBCC DBREINDEX (TableC,'', 70)

    GO

    SELECT GETDATE() AS EndTime

    GO

    Thanks, Kevin

  • Both look good. I feel GetDate() would be more apt.

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

  • If you're going to do it that way then getdate() is the best way to go.

    However, I normally query the msdb..sysjobhistory table to get the starttime (warning, run_date and run_time are stored as integers, in the format yyyymmdd and hhmmss respectively) and the duration (stored in seconds).

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply