I have a database where I create a new table every day and fill it with data (I know this isn't ideal, but I can't change this). Each table is of the form "TESTdata_xxxxx_DB", where xxxxx is incremented by 1 every day.
I need a simple way to select the top 1000 rows (where a specific condition is met) across many of those tables (i.e. across many dates). For example, I need to query across tables TESTdata_45800_DB, TESTdata_45801, ..., TESTdata_45850_DB.
I have tried the following query, but clearly adding "to" doesn't work, and separating them by comma doesn't combine them the way I want:
SELECT TOP 1000
[ItemIndex],
[Data1],
[Data2],
[Data3]
FROM
[TESTDB1].[dbo].[TESTdata_45800_DB] (to...) [TESTdata_45850_DB]
WHERE
Data1 LIKE 'High' OR Data1 LIKE 'Medium'
ORDER BY
Data1
;
Any help would be appreciated.