WITH cte AS(SELECT *FROM lmadmindb..tbl_mssql_errorlog_currentWHERE (text like 'Error:%' OR text like 'Msg %') and text not like '%18456%')SELECT beforeCurrent.*into SomeNewTableFROM cteOUTER APPLY(SELECT *FROM lmadmindb..tbl_mssql_errorlog_current eWHERE e.logdate = cte.LogDate) beforeCurrent
WITH cte AS(SELECT *FROM lmadmindb..tbl_mssql_errorlog_currentWHERE (text like 'Error:%' OR text like 'Msg %') and text not like '%18456%')Insert into SomeTableSELECT beforeCurrent.*FROM cteOUTER APPLY(SELECT *FROM lmadmindb..tbl_mssql_errorlog_current eWHERE e.logdate = cte.LogDate) beforeCurrent