Building a Time Dimension Copyright © 2001 by Michael A. Mina.
-
Upload
emma-cross -
Category
Documents
-
view
212 -
download
0
Transcript of Building a Time Dimension Copyright © 2001 by Michael A. Mina.
![Page 1: Building a Time Dimension Copyright © 2001 by Michael A. Mina.](https://reader036.fdocuments.net/reader036/viewer/2022082917/551519475503465e608b5004/html5/thumbnails/1.jpg)
Building a Time Dimension
Copyright © 2001 by Michael A. Mina
![Page 2: Building a Time Dimension Copyright © 2001 by Michael A. Mina.](https://reader036.fdocuments.net/reader036/viewer/2022082917/551519475503465e608b5004/html5/thumbnails/2.jpg)
Copyright © 2001 by Michael A. Mina 2
Create (manually or otherwise) one table listing the digits 0 through 9.
![Page 3: Building a Time Dimension Copyright © 2001 by Michael A. Mina.](https://reader036.fdocuments.net/reader036/viewer/2022082917/551519475503465e608b5004/html5/thumbnails/3.jpg)
Copyright © 2001 by Michael A. Mina 3
SELECT 1000*A.Digit+100*B.Digit+10*C.Digit+D.Digit AS DateKey, DateAdd("d",1000*A.Digit+100*B.Digit+10*C.Digit+D.Digit,#01/01/1990#) AS DateValue INTO DateValuesFROM Digits AS A, Digits AS B, Digits AS C, Digits AS DORDER BY 1;
Write a cross join query to create a Cartesian product of the table with itself four times.
Our SELECT statement will use the Cartesian product to create the integers 0 through 10,000.
The DateAdd function will add these integers to a starting date (in this case, 1/1/1990).
Different databases may use a different function to add integers to dates.
![Page 4: Building a Time Dimension Copyright © 2001 by Michael A. Mina.](https://reader036.fdocuments.net/reader036/viewer/2022082917/551519475503465e608b5004/html5/thumbnails/4.jpg)
Copyright © 2001 by Michael A. Mina 4
![Page 5: Building a Time Dimension Copyright © 2001 by Michael A. Mina.](https://reader036.fdocuments.net/reader036/viewer/2022082917/551519475503465e608b5004/html5/thumbnails/5.jpg)
Copyright © 2001 by Michael A. Mina 5
SELECT DateKey, DateValue, Day(DateValue) AS Day, Month(DateValue) AS Month, Int((Month(DateValue)+2)/3) AS Quarter, Year(DateValue) AS Year INTO TimeDimensionFROM DateValues;
Create a Time dimension table using the previous table.
Use the row functions provided by your database to add the information you need.
Remember to create a primary key on the Time dimension table.
![Page 6: Building a Time Dimension Copyright © 2001 by Michael A. Mina.](https://reader036.fdocuments.net/reader036/viewer/2022082917/551519475503465e608b5004/html5/thumbnails/6.jpg)
Copyright © 2001 by Michael A. Mina 6