mardi 3 janvier 2017

Sql how to switch tables

i am new in SQL, I use MS Server.

I have two tables one of them have historical(cdr_hist) data other table have data from today(cdr_stage). My script must run every 30 minutes and calculate data from last 4 hours but every night at 12 all data move at cdr_hist.

The question is how I can switch and take data from history table when script run at 12:00 because cdr_stage is empty... I try This:

IF  OBJECT_ID   ('[**CDR_Stage**]') IS NOT NULL 
BEGIN
    Select.....
    From **CDR_Stage**
END
ELSE
    Select.....
    From **CDR_Hist**
END

But its not work correctly... Any ideas??

Aucun commentaire:

Enregistrer un commentaire