Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Restituire i dati prima del mese corrente

Ottieni tutti i nomi delle tabelle da INFORMATION_SCHEMA.TABLES. Quindi applica i tuoi criteri per ottenerli:

select table_name
from information_schema.tables
where table_type = 'BASE TABLE'
and table_name like 'xx\_______\_T' escape '\'  
and table_name >= 'xx_' + CAST(@FirstTableMonth as varchar) + '_T';

Fiddle SQL:http://www.sqlfiddle.com/#!6/7b4f5/ 2