Skip to content
Advertisement

Select from dynamic table

I need to run a query in sql that depending on the month and year I need to call a different table.

For example:

If current_date is 31/08/2020, execute: select * from table_ago

If current_date is 01/09/2020, execute: select * from table_sep

Is it posible using a query in SQL Server?

Advertisement

Answer

You can use a stored procedure and if condition to make possible such a thing like following

Now run the procedure like follow

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement