Search SQL Error Logs using TSQL – xp_readerrorlog


--
exec xp_readerrorlog 0	-- 0=current SQLServer log
,1 -- 1=SQL Server log, 2=SQL Agent log
,N'availability group'					-- Search string
,null					-- second search string
,'2013-11-10 15:30:39.083'			-- start date
,'2013-11-11 15:30:39.083'	-- end date
,N'DESC'				-- order the logs by date
--

-- Option.B


DECLARE @enddate datetime
DECLARE @startdate datetime

SET @enddate = getdate() 
SET @startdate = dateadd(hh,-24,getdate() )


exec xp_readerrorlog 0  -- 0=current SQLServer log
,1 -- 1=SQL Server log, 2=SQL Agent log
,N''                  -- Search string
,null                   -- second search string
,@startdate         -- start date
,@enddate  -- end date
,N'DESC'   


Advertisements
This entry was posted in Productivity, Script, SQL, SQL Server, Uncategorized and tagged , , . Bookmark the permalink.

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