Home > SQL Scripts > Reading Error Log (Parameterized)

Reading Error Log (Parameterized)

Read specific date, time and text error log. This help while troubleshooting issue on a highly transaction SQL Server.

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

You can also use
xp_readerrorlog 0, 1,NULL, NULL, ’12-11-2012 15:40:00′, ’12-11-2012 23:40:00′, N’asc’

Categories: SQL Scripts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: