http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/95820/ Update statistics on tables not empty and with statistics older than 3 days SELECT t.name AS [tname] , ' update statistics [' + t.name + ']; ' [comando] FROM sys.tables t LEFT JOIN sys.stats s ON t.object_id = s.object_id JOIN ( SELECT object_id , SUM(ROWS) ROWS FROM sys.partitions GROUP BY object_id HAVING SUM(ROWS) >0 ) pa ON t.object_id = pa.object_id WHERE ( STATS_DATE(t.object_id, stats_id) IS NULL OR datediff(DAY, STATS_DATE(t.object_id, stats_id), GETDATE() ) >= 3 ) GROUP BY t.name ORDER BY 1