Necessary Modification: There are some tables you do not want to monitor for various reasons. To remove these tables from the results set, get their table ID from vol.Tables and insert them into the UnwantedTables temporary table.
--Remove Rarely loaded tables from load analysisINSERT INTO #UnWantedTables(TableID)SELECT131UNION ALLSELECT135UNION ALLSELECT118UNION ALLSELECT123
USE [ODS]GODROPPROCEDUREIFEXISTS [dbo].[usp_LoadTableLoadReportingTable]GOSETANSI_NULLSONGOSETQUOTED_IDENTIFIERONGOCREATEPROCEDURE [dbo].[usp_LoadTableLoadReportingTable] ASBEGINCREATETABLE #UnWantedTables(TableID INT)CREATECLUSTEREDINDEX CIDX_UNWANTEDTABLES_TABLEID ON #UnWantedTables(TableID)DECLARE @MostRecentDate DATETIMEDECLARE @MostRecentDateInReportingTable DATESELECT @MostRecentDate =MAX(DateOfCurrentObservation) FROM [vol].[LoadObservations]SELECT @MostRecentDateInReportingTable =MAX(DateOfCurrentObservation) FROM rpt.TableLoadReportINSERT INTO #UnWantedTables(TableID)--Get rid of tables with no recordsSELECT t.TableIDFROM [vol].[Tables] tJOIN [vol].[LoadObservations] loON t.TableID = lo.TableIDGROUP BY t.TableIDHAVINGAVG(CAST(lo.[RowCount] ASBIGINT)) =0UNION--Get rid of tables with no load varianceSELECT t.TableIDFROM [vol].[Tables] tJOIN [vol].[LoadObservations] loON t.TableID = lo.TableIDGROUP BY t.TableIDHAVINGAVG(CAST(lo.CurrentThreeSDLevel ASBIGINT)) =0--Remove Rarely loaded tables from load analysis--INSERT INTO #UnWantedTables(TableID)--SELECT 131--UNION ALL--SELECT 135--UNION ALL--SELECT 118--UNION ALL--SELECT 123IFISNULL(@MostRecentDateInReportingTable,'19000101') <>CAST(CURRENT_TIMESTAMP ASDATE)BEGININSERT INTO rpt.TableLoadReport(TableName, DateOfCurrentObservation, DateOfLastObservation, [RowCount], ChangeFromLastObservation, CurrentThreeSDLevel,AsOf)SELECTt.TableName, lo.DateOfCurrentObservation, lo.DateOfLastObservation, lo.[RowCount], lo.ChangeFromLastObservation, lo.CurrentThreeSDLevel,CAST(CURRENT_TIMESTAMP ASDATE)FROM vol.Tables tJOIN vol.LoadObservations loON t.TableID = lo.TableIDWHERE lo.CurrentThreeSDLevel IS NOT NULLAND t.TableID NOTIN (SELECT TableId FROM #UnWantedTables)ORDER BY t.TableName, lo.DateOfCurrentObservation ASCENDDROPTABLE #UnWantedTablesENDGO