Thursday, May 14, 2009

SQL Server Querying Error Logs Between Dates

We've all experienced the SA or NOC center sending us some java log pointing an SQL Error. First thing I do is look inside the error log at that time to see if something big had occurred. The following script is used to pinpoint issues based on time.


 

Declare @StartTime datetime

Declare @EndTime datetime


 

--Set Criteria her

Set @StartTime =
'5/14/2009 4:50:00'

Set @EndTime =
'5/14/2009 5:50:00'


 

Create
table #logTable

(LogDate datetime,

ProcessInfo varchar(10),

TextOut varchar(1000))


 


 

insert
into #logTable

EXEC master.dbo.xp_readerrorlog 0, 1,
null
,
null,
NULL,
NULL, N'desc'


 


 

Select
*
from #logTable

where LogDate between @StartTime and @EndTime

order
by LogDate desc

No comments: