1

AdventureWorksDWデータベースにあるDimTimeまたはDimDateテーブルに代わる無料のダウンロード方法はありますか?このテーブルだけが欲しい。さらに、将来的には50年または100年が好きになるのは素晴らしいことです。

ありがとう、シム

4

2 に答える 2

1

得られた応答に満足しているかどうかはわかりませんが、ビジネス要件に基づいて独自の DimDate テーブルを作成することもできます。AdventureWorksDW212 DimDate テーブル構造に基づいて、次のコードを作成しました。

    --change [YourDatabase] to your database's name
    USE [YourDatabase] 
    GO

    --First Create the Table (dbo.DimDate)
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    IF OBJECT_ID('dbo.DimDate') IS NOT NULL
    DROP TABLE dbo.DimDate;

    CREATE TABLE [dbo].[DimDate](
        [DateKey] [int] NOT NULL,
        [FullDateAlternateKey] [date] NOT NULL,
        [DayNumberOfWeek] [tinyint] NOT NULL,
        [EnglishDayNameOfWeek] [nvarchar](10) NOT NULL,
        [SpanishDayNameOfWeek] [nvarchar](10) NOT NULL,
        [FrenchDayNameOfWeek] [nvarchar](10) NOT NULL,
        [DayNumberOfMonth] [tinyint] NOT NULL,
        [DayNumberOfYear] [smallint] NOT NULL,
        [WeekNumberOfYear] [tinyint] NOT NULL,
        [EnglishMonthName] [nvarchar](10) NOT NULL,
        [SpanishMonthName] [nvarchar](10) NOT NULL,
        [FrenchMonthName] [nvarchar](10) NOT NULL,
        [MonthNumberOfYear] [tinyint] NOT NULL,
        [CalendarQuarter] [tinyint] NOT NULL,
        [CalendarYear] [smallint] NOT NULL,
        [CalendarSemester] [tinyint] NOT NULL,
        [FiscalQuarter] [tinyint] NOT NULL,
        [FiscalYear] [smallint] NOT NULL,
        [FiscalSemester] [tinyint] NOT NULL,
     CONSTRAINT [PK_DimDate_DateKey] PRIMARY KEY CLUSTERED 
    (
        [DateKey] ASC
    )
        WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
        IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 
        ON [PRIMARY],
        CONSTRAINT [AK_DimDate_FullDateAlternateKey] UNIQUE NONCLUSTERED 
    (
        [FullDateAlternateKey] ASC
    )
        WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
        IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 
        ON [PRIMARY]
    ) ON [PRIMARY]

      GO
    --I have used the table structure to resemble the DimDate table 
    --in the AdventureWorksDW2012 DB but you can modify to meet your needs
    --After the table is created, use the following code to populate the table:

    --Create a DATE type variable (@StartDate) to hold the start date
    DECLARE @StartDate AS DATE; 

    --Create another DATE Type variable (@EndDate) to hold the end date
    DECLARE @EndDate AS DATE;

    --Initialize @StartDate
    SET @StartDate = '2015-01-01';

    --Initialize @EndDate
    SET @EndDate = '2020-12-31';

    WHILE (@StartDate <= @EndDate)
    BEGIN

    --When populating the DimDate table,
    --Use a set operation because it is much faster than the regular "INSERT INTO" operation!

    INSERT dbo.DimDate 

    SELECT
        CONVERT(char(8), @StartDate, 112) AS DateKey, 
        CONVERT(char(10), @StartDate, 126) AS FullDateAlternateKey, 
        DATEPART(DW, @StartDate) AS DayNumberOfWeek, 
        DATENAME(DW, @StartDate) AS EnglishDayNameOfWeek,

        CASE 
            WHEN DATENAME(DW, @StartDate) = 'Saturday'  THEN 'Sábado'
            WHEN DATENAME(DW, @StartDate) = 'Sunday'    THEN 'Domingo'
            WHEN DATENAME(DW, @StartDate) = 'Monday'    THEN 'Lunes'
            WHEN DATENAME(DW, @StartDate) = 'Tuesday'   THEN 'Martes'
            WHEN DATENAME(DW, @StartDate) = 'Wednesday' THEN 'Miércoles'
            WHEN DATENAME(DW, @StartDate) = 'Thursday'  THEN 'Jueves'
            WHEN DATENAME(DW, @StartDate) = 'Friday'    THEN 'Viernes'
            END AS SpanishDayNameOfWeek,

        CASE 
            WHEN DATENAME(DW, @StartDate) = 'Saturday'  THEN 'Samedi'
            WHEN DATENAME(DW, @StartDate) = 'Sunday'    THEN 'Dimanche'
            WHEN DATENAME(DW, @StartDate) = 'Monday'    THEN 'Lundi'
            WHEN DATENAME(DW, @StartDate) = 'Tuesday'   THEN 'Mardi'
            WHEN DATENAME(DW, @StartDate) = 'Wednesday' THEN 'Mercredi'
            WHEN DATENAME(DW, @StartDate) = 'Thursday'  THEN 'Jeudi'
            WHEN DATENAME(DW, @StartDate) = 'Friday'    THEN 'Vendredi'
            END AS FrenchDayNameOfWeek,

            DATEPART(DD, @StartDate) AS DayNumberOfMonth, 
            DATEPART(dayofyear, @StartDate) AS DayNumberOfYear,
            DATEPART(WK, @StartDate) AS WeekNumberOfYear,
            DATENAME(MONTH, @StartDate) AS EnglishMonthName,

        CASE 
            WHEN DATENAME(MONTH, @StartDate) = 'January'    THEN'Enero'
            WHEN DATENAME(MONTH, @StartDate) = 'February'   THEN 'Febrero'
            WHEN DATENAME(MONTH, @StartDate) = 'March'      THEN    'Marzo'
            WHEN DATENAME(MONTH, @StartDate) = 'April'      THEN 'Abril'
            WHEN DATENAME(MONTH, @StartDate) = 'May'        THEN 'Mayo'
            WHEN DATENAME(MONTH, @StartDate) = 'June'       THEN 'Junio'
            WHEN DATENAME(MONTH, @StartDate) = 'July'       THEN 'Julio'
            WHEN DATENAME(MONTH, @StartDate) = 'August'     THEN 'Agosto'
            WHEN DATENAME(MONTH, @StartDate) = 'September'  THEN 'Septiembre'
            WHEN DATENAME(MONTH, @StartDate) = 'October'    THEN 'Octubre'
            WHEN DATENAME(MONTH, @StartDate) = 'November'   THEN 'Noviembre'
            WHEN DATENAME(MONTH, @StartDate) = 'December'   THEN 'Diciembre'
            END AS SpanishMonthName,

        CASE 
            WHEN DATENAME(MONTH, @StartDate) = 'January'    THEN 'Janvier'
            WHEN DATENAME(MONTH, @StartDate) = 'February'   THEN 'Février'
            WHEN DATENAME(MONTH, @StartDate) = 'March'      THEN 'Mars'
            WHEN DATENAME(MONTH, @StartDate) = 'April'      THEN 'Avril'
            WHEN DATENAME(MONTH, @StartDate) = 'May'        THEN 'Mai'
            WHEN DATENAME(MONTH, @StartDate) = 'June'       THEN 'Juin'
            WHEN DATENAME(MONTH, @StartDate) = 'July'       THEN 'Juillet'
            WHEN DATENAME(MONTH, @StartDate) = 'August'     THEN 'Août'
            WHEN DATENAME(MONTH, @StartDate) = 'September'  THEN 'Septembre'
            WHEN DATENAME(MONTH, @StartDate) = 'October'    THEN 'Octobre'
            WHEN DATENAME(MONTH, @StartDate) = 'November'   THEN 'Novembre'
            WHEN DATENAME(MONTH, @StartDate) = 'December'   THEN 'Décembre'
            END AS FrenchMonthName,

            DATEPART(MONTH, @StartDate) AS MonthNumberOfyear,
            DATEPART(Quarter, @StartDate) AS CalendarQuarter,
            YEAR(@StartDate) AS CalendarYear,

        CASE 
            WHEN DATEPART(MONTH, @StartDate) IN (1,2,3,4,5,6)
            THEN 1
            WHEN DATEPART(MONTH, @StartDate) IN (7,8,9,10,11,12)
            THEN 2
            END AS CalendarSemester,

        CASE 
            WHEN DATEPART(MONTH, GetDATE()) IN (7, 8, 9)    THEN 1
            WHEN DATEPART(MONtH, GetDATE()) IN (10, 11, 12) THEN 2
            WHEN DATEPART(MONtH, GetDATE()) IN (1, 2, 3)    THEN 3
            WHEN DATEPART(MONtH, GetDATE()) IN (4, 5, 6)    THEN 4
            END AS FiscalQuarter,

        CASE 
            WHEN MONTH(@StartDate) < 7  THEN YEAR(@StartDate) --Assuming the fiscal year beings on the first of July 
            ELSE YEAR(@StartDate) + 1 --if the date is less than July, then the Fiscal Year is equal to the Calendar Year
            END AS FiscalYear,

        CASE 
            WHEN DATEPART(MONTH, @StartDate) IN (7,8,9,10,11,12)    THEN 1
            WHEN DATEPART(MONTH, @StartDate) IN (1,2,3,4,5,6)       THEN 2
            END AS FiscalSemester

            --Increment the @StartDate by 1 here:
            SET @StartDate = DATEADD(DAY, 1, @StartDate);

    END

    --You can now test your code by selecting from the table:
    SELECT * FROM DimDate;
于 2014-11-14T16:57:49.950 に答える
0

ETL ソフトウェアを使用して、その種のテーブルを自分で生成できます。たとえば、Pentaho ETLでは、時間ディメンションを作成する変換の例にする必要があります。そのようなソフトウェアを使用すると、出力形式を選択することが可能になります。そのようなソフトウェアを使用すると、出力形式を選択することができます。

于 2012-07-12T13:43:18.597 に答える