Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE [DIM_TIME](
- TimeID int CONSTRAINT PK_DIM_TIME PRIMARY KEY,
- [Year] int NOT NULL,
- [Month] varchar(10) NOT NULL,
- MonthDay int NOT NULL,
- [Weekday] varchar(10) NOT NULL,
- [Hour] int Not Null
- );
- --Repos
- SET DATEFIRST 1;
- INSERT INTO [DIM_TIME]
- Select distinct r.created as timeid, lefT(r.created, 4) as year, DATENAME(month, cast(cast(left(r.created,8) as varchar(10)) as date)) as month,
- left(right(r.created, 4), 2) as day , DATENAME(dw, cast(cast(left(r.created,8) as varchar(10)) as date)) as dayweek, RIGHT(r.created,2) as hour
- from [FACT_REPOSITORY] as r
- union
- Select distinct r.CreationDate as timeid, lefT(r.CreationDate, 4) as year, DATENAME(month, cast(cast(left(r.CreationDate,8) as varchar(10)) as date)) as month,
- left(right(r.CreationDate, 4), 2) as day , DATENAME(dw, cast(cast(left(r.CreationDate,8) as varchar(10)) as date)) as dayweek, RIGHT(r.CreationDate,2) as hour
- from [FACT_QUESTION] as r
- union
- Select distinct r.CreationDate as timeid, lefT(r.CreationDate, 4) as year, DATENAME(month, cast(cast(left(r.CreationDate,8) as varchar(10)) as date)) as month,
- left(right(r.CreationDate, 4), 2) as day , DATENAME(dw, cast(cast(left(r.CreationDate,8) as varchar(10)) as date)) as dayweek, RIGHT(r.CreationDate,2) as hour
- from [FACT_ANSWER] as r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement