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 tried 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??