Reading Error Log (Parameterized)

Read SQL Server Error log with date time and string filter.

SET DATEFORMAT DMY

DECLARE @StartDateTime Varchar(30)='15/11/2012 23:40:00'
DECLARE @EndDateTime Varchar(30)='29/11/2012 23:59:00'
DECLARE @SearchString nvarchar(MAX)=''

DECLARE @ReadCurrentSQLErrorLog TABLE
(LogDate DATETIME,
ProcessInfo VARCHAR(20),
Text VARCHAR(500)
)

INSERT INTO @ReadCurrentSQLErrorLog
EXEC master.dbo.xp_readerrorlog 0

SELECT * FROM @ReadCurrentSQLErrorLog
WHERE LogDate >= CONVERT(datetime,@StartDateTime)
AND LogDate < CONVERT(datetime,@EndDateTime)
AND text like '%'+@SearchString+'%'
ORDER BY LogDate DESC
[/code]
You can also use


go

xp_readerrorlog 0, 1,NULL, NULL, '12-11-2012 15:40:00', '12-11-2012 23:40:00', N'asc'

go

Leave a Reply

Your email address will not be published. Required fields are marked *