Skip to main content
Formatting
Source Link
Arthur D
  • 932
  • 5
  • 10

How about you use a view, and change the definition of the view as the months change, on a scheduled job? You would just do all queries against this view, to make sure you're always getting the latest data.

Example:

CREATE VIEW 
           dbo.Sessions_month 
       AS 
           (SELECT Columns FROM Sessions_month_1) 
       GO

Then your job would do something like this:

USE your-database
GO
DECLARE @SQL NVARCHAR(max)
SET @SQL = 'ALTER VIEW dbo.Sessions_month AS 
            (SELECT Columns FROM Sessions_month_' 
           + month(getdate()) + ')'

EXEC (@SQL)

How about you use a view, and change the definition of the view as the months change, on a scheduled job? You would just do all queries against this view, to make sure you're always getting the latest data.

Example:

CREATE VIEW 
           dbo.Sessions_month 
       AS 
           (SELECT Columns FROM Sessions_month_1) 
GO

Then your job would do something like this:

USE your-database
GO
DECLARE @SQL NVARCHAR(max)
SET @SQL = 'ALTER VIEW dbo.Sessions_month AS 
            SELECT Columns FROM Sessions_month_' 
           + month(getdate())

EXEC (@SQL)

How about you use a view, and change the definition of the view as the months change, on a scheduled job? You would just do all queries against this view, to make sure you're always getting the latest data.

Example:

CREATE VIEW 
           dbo.Sessions_month 
       AS 
           (SELECT Columns FROM Sessions_month_1) 
       GO

Then your job would do something like this:

USE your-database
GO
DECLARE @SQL NVARCHAR(max)
SET @SQL = 'ALTER VIEW dbo.Sessions_month AS 
            (SELECT Columns FROM Sessions_month_' 
           + month(getdate()) + ')'

EXEC (@SQL)
Source Link
Arthur D
  • 932
  • 5
  • 10

How about you use a view, and change the definition of the view as the months change, on a scheduled job? You would just do all queries against this view, to make sure you're always getting the latest data.

Example:

CREATE VIEW 
           dbo.Sessions_month 
       AS 
           (SELECT Columns FROM Sessions_month_1) 
GO

Then your job would do something like this:

USE your-database
GO
DECLARE @SQL NVARCHAR(max)
SET @SQL = 'ALTER VIEW dbo.Sessions_month AS 
            SELECT Columns FROM Sessions_month_' 
           + month(getdate())

EXEC (@SQL)