select name from sysobjects where crDate <= @Date AND type = 'S'
select name from sysobjects where crDate <= @Date AND type = 'U'
DECLARE OldTablesCur CURSOR READ_ONLY FOR select name from sysobjects where xtype like 'U' and crdate<@YourDate DECLARE @name varchar(40) OPEN OldTablesCur FETCH NEXT FROM OldTablesCur INTO @name WHILE (@@fetch_status <> -1) BEGIN IF (@@fetch_status <> -2) BEGIN EXEC ('PRINT '''+@name+'''') --EXEC ('drop table '+@name) END FETCH NEXT FROM OldTablesCur INTO @name END CLOSE OldTablesCur DEALLOCATE OldTablesCur GO
exec sp_MSForEachTable N'if ''?'' in (select ''[dbo].[''+name+'']'' from sysobjects where xtype like ''U'' and crdate<''20060901'') drop table ''?'''