I have tables with names:
DeviceLogs_1_2023
DeviceLogs_2_2023
Every month new table is added in database.
How can I create a procedure to combine data from multiple tables into one table or view?
select * from DeviceLogs_7_2022
union all
select * from DeviceLogs_8_2022
Any solution relies on the schema staying stable (generally you don't want to use
*in views, because funny things happen if you add / drop / rename columns). This specific solution assumes you are on SQL Server 2017 or better (or Azure SQL Edge / Azure SQL Database / Managed Instance). You should always tag the question with the minimum version you need to support.