Skip to content

Instantly share code, notes, and snippets.

@richardbasile
Created February 16, 2018 14:00
Show Gist options
  • Save richardbasile/c645c3237ca26d023a1d8dd37d9bc28f to your computer and use it in GitHub Desktop.
Save richardbasile/c645c3237ca26d023a1d8dd37d9bc28f to your computer and use it in GitHub Desktop.
SQL Server - Failed Logins
declare @Time_Start datetime = getdate()-7;
declare @Time_End datetime = getdate();
-- Create the temporary table
DECLARE @ErrorLog TABLE (logdate datetime
, processinfo varchar(255)
, Message varchar(500))
-- Populate the temporary table
INSERT @ErrorLog (logdate, processinfo, Message)
EXEC master.dbo.xp_readerrorlog 0, 1, null, null , @Time_Start, @Time_End, N'desc';
-- Filter the temporary table
SELECT * --LogDate, Message
FROM @ErrorLog
WHERE (Message LIKE '%error%' OR Message LIKE '%failed%')
ORDER BY logdate DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment