数据仓库的时间维度表 Sql

 
  Declare @BeginDate Datetime
  Set @BeginDate='2011-1-1'
  While @BeginDate<'2015-12-31'
  Begin
  Insert Into [InstagramDataDW].[dbo].[Dim_Date]
  Select CONVERT(varchar(10),@BeginDate,112) As DateKey,Year(@BeginDate) as Year,
  Case When Month(@BeginDate)>6 then 2 Else 1 End As HalfYear,
  DATEPART(QUARTER,@BeginDate) As Quarter,
  Case  When DATEPART(QUARTER,@BeginDate)=1 Then 'one'
When DATEPART(QUARTER,@BeginDate)=2 Then 'two'
When DATEPART(QUARTER,@BeginDate)=3 Then 'three'
  Else 'four' End As QuarterEN,
  Month(@BeginDate) As Month,
  DATEPART(WEEK,@BeginDate) As [WeekOfYear],
  DateName(WEEKDAY,@BeginDate) As Week,
  Day(@BeginDate) As Day,
  CONVERT(varchar(10),@BeginDate,120) As Date
    Set @BeginDate=DATEADD(DAY,1,@BeginDate)
End

你可能感兴趣的:(数据仓库的时间维度表 Sql)