Thanks Homebrew,
I tried giving '' quotes but its failing with the below message:
(95 row(s) affected)
Msg 22050, Level 16, State 1, Line 0
Error formatting query, probably invalid parameters
Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 504
Query execution failed: Msg 208, Level 16, State 1, Server EW1\INS1, Line 1
Invalid object name '#ErrorLog'.
CREATE TABLE #ErrorLog (
LogDate DATETIME,
ProcessInfo NVARCHAR(255),
LogText NVARCHAR(MAX)
)
INSERT INTO #ErrorLog (
[LogDate],
[ProcessInfo],
[LogText]
)
EXEC xp_readerrorlog
declare @query nvarchar(max)
set @query='select left(@@servername,20) as server, left(LogDate,20),[LogText] from #ErrorLog
where ProcessInfo !=''Logon''
and LogText not like ''Database backed up%''
and LogText not like ''Log was backed up%''
and LogText not like ''%found 0 errors%''
and LogText not like ''This instance of SQL Server has been using a process ID%''
and LogText not like ''Configuration option ''''user options'''' changed from 0 to 0. Run the RECONFIGURE statement to install.''
and LogText not like ''Microsoft SQL Server 200%''
and LogText not like ''(c) %''
and LogText not like ''All rights rese%''
and LogText not like ''Server process ID is%''
and LogText not like ''System Manufacturer:%''
and LogText not like ''Authentication mode is %''
and LogText not like ''Logging SQL Server messages in file%''
and LogText not like ''This instance of SQL Server last reported using a process ID o%''
and LogText not like ''Registry startup parameters:%''
and LogText not like ''SQL Server is starting at normal priority base%''
and LogText not like ''Detected % CPUs. This is an informational messag%''
and LogText not like ''Using locked pages for buffer pool%''
and LogText not like ''Using dynamic lock allocation.%''
and LogText not like ''Node configuration: node 0: CPU mask%''
and LogText not like ''Setting database option COMPATIBILITY_LEVEL to 100%''
and LogText not like ''Setting database option COMPATIBILITY_LEVEL to 100 for database ReportServerTempDB.''
and LogText not like ''Server is listening on %''
and LogText not like ''Server local connection provider is ready to accept connection on%''
and LogText not like ''The SQL Server Network Interface library successfully registered the Service Principal Name%''
and LogText not like ''Service Broker manager has started.''
and LogText not like ''Starting up database%''
and LogText not like ''CHECKDB for database % finished without errors on %''
and LogText not like ''FILESTREAM: effective level = 0, configured level = 0%''
and LogText not like ''AppDomain % unloaded.''
and LogDate> DATEADD(hh, - 1, GETDATE()) '
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'dbmail',
@recipients = 'abc@abc.com',
@query = @query,
@subject = 'error found in errorlog'
drop table #ErrorLog