954,160 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Converting datetime to int

This set of code below shows all SQL Server Agent jobs that have failed for the date 200.03.29. The run_date column is an integer, but I want to run the code in such a way that the resultset is automatically generated for the day before the current date.

The code that works is below:

select [name] as [Job Name],[server] as  [Server], step_id, step_name, [message] as [Error], 
  run_date as [Date Started], run_time as [Time Started], run_duration as [Duration] 
from sysjobs join sysjobhistory on sysjobs.job_id = sysjobhistory.job_id	
where run_date = 20090329
and run_status = 0


How can I change this so that run_date will get the equivalent integer value representing the day before the current date?

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

CONVERT (varchar, GETDATE() - 1, 112) will give you yesterdays date in that format

squarefish
Newbie Poster
1 post since Mar 2009
Reputation Points: 10
Solved Threads: 0
 
CONVERT (varchar, GETDATE() - 1, 112) will give you yesterdays date in that format


Thanks, but I wanted it as an INTEGER, not a varchar... the script references the sysjobhistory table in the msdb database, and, in that table, the run_date column is an integer.

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You