I want to pass a variable to a table name in SQL Server. I have tables that have date stamps on them, followed by an alpha character:
EO_PurcheseOrder_11252022P
EO_PurcheseOrder_12022022P
EO_PurcheseOrder_12152022P
EO_PurcheseOrder_12202022P
etc.
More tables are added in this format every week. I want to be able to write a header at the top of my code where the user can input a date and then the code will add the MMDDYYYY throughout the code in the table names.
I want to start my code with a
Declare @Table_Date INT;
set @Table_Date = 12152022
or
Declare @Table_Date VARCHAR(9);
set @Table_Date = 12152022P
But how would I pass that @Table_Date to the table name in the code? An example would be:
select *
into DRX.earlyorderNJ_DX_2022
from DRX.EO_PurcheseOrder_11252022P