The following script works in Oracle and creates a table - actually a view - to be used as time dimension.
create or replace view timedimension
as
select
to_date('2009-01-01', 'YYYY-MM-DD') + level - 1 dt
from
dual
connect by
level <= trunc(current_date, 'DDD') - to_date('2009-01-01', 'YYYY-MM-DD') + 1;
/
The table contains one record per day and the dates run from 2009-01-01 till present, keeping it as small as possible - which will come handy when joining in queries.
Subscribe to:
Post Comments (Atom)
very nice solution, much neater than the solution I found in use on a client site yesterday - they've half hourly grain data for every 30 mins between 1900 and 2100 generated by an Excel VBA macro, surprisingly quite a few rows!
ReplyDeletehttp://www.cognosdev.wordpress.com/