Delete Report Temp Tables from MAX Database

Here’s a quick script to delete the temp tables from your MAX database.

USE — Your MAX DB Name i.e. ExactMAXSample

DECLARE @NAME AS NVARCHAR(50);
DECLARE @CMD AS NVARCHAR(50);

DECLARE C CURSOR FAST_FORWARD FOR
select TABLE_NAME from INFORMATION_SCHEMA.TABLES
where
TABLE_NAME Like ‘09%’ or
TABLE_NAME Like ‘10%’ or
TABLE_NAME Like ‘11%’ or
TABLE_NAME Like ‘12%’ or
TABLE_NAME Like ‘13%’ or
TABLE_NAME Like ‘14%’ or
TABLE_NAME Like ‘15%’ or
TABLE_NAME Like ‘16%’ or
TABLE_NAME Like ‘17%’ or
TABLE_NAME Like ‘18%’ or
TABLE_NAME Like ‘19%’ or
TABLE_NAME Like ‘20%’ or
TABLE_NAME Like ‘21%’ or
TABLE_NAME Like ‘22%’ or
TABLE_NAME Like ‘MRP_Explosion_%’ or
TABLE_NAME Like ‘Extract_%’ or

OPEN C
FETCH NEXT FROM C INTO @NAME;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @CMD = ‘DROP TABLE ‘ + ‘[‘ + ‘dbo’ + ‘]’ + ‘.’ + ‘[‘ + @NAME +’]’;
EXEC SP_EXECUTESQL @CMD
FETCH NEXT FROM C INTO @NAME
END
CLOSE C;
DEALLOCATE C;

About Vincent Stefanetti

Vincent Stefanetti Senior Consultant MAX Manufacturing Software Working with MAX and Related Technologies Since 1987 MAX ERP System Implementations and Projects MAX, Dynamics GP, Synergy, Event Manager, Crystal Reports, SQL Reporting Services, Database and System Migrations and Updates, MAX Training Classes - All Levels, Custom Reporting.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *