I'm trying to have the FROM statement in a SQL query result in a different database depending on the date.
In the middle of each month, our system puts the most recent data in a NEXT database, then at the beginning of the next month NEXT is put into CURRENT and NEXT is emptied.
I want my query to always use the most up-to-date database, or from the first to the 20th use CURRENT, thereafter use NEXT. I've tried to do this with a CASE statement, but I keep getting syntax errors.
Here's a sample of the query that failed:
Does anyone have an idea of how I can put a condition in my FROM statement?
Thanks,
Dante
In the middle of each month, our system puts the most recent data in a NEXT database, then at the beginning of the next month NEXT is put into CURRENT and NEXT is emptied.
I want my query to always use the most up-to-date database, or from the first to the 20th use CURRENT, thereafter use NEXT. I've tried to do this with a CASE statement, but I keep getting syntax errors.
Here's a sample of the query that failed:
Code:
SELECT stuff.id FROM case when day(getdate())>19 then CURRENT.dbo.facts else NEXT.dbo.facts end as stuff
Thanks,
Dante
Comment