zoukankan      html  css  js  c++  java
  • 生成日期基础表

    ----------------------------------
    --生成日期基础表
    ----------------------------------
    -- 设置每周的起始天为周一
    SET DATEFIRST 1
    IF OBJECT_ID('Base_DateTimeInfo','U') IS NOT NULL
    DROP TABLE Base_DateTimeInfo
    GO
    
    CREATE TABLE Base_DateTimeInfo
    (
        DateKey INT PRIMARY KEY,
        DateTime DATE NOT NULL,
        [DateName] NVARCHAR(20),
        DayNumberOfWeek TINYINT NOT NULL,
        DayNameOfWeek NVARCHAR(10) NOT NULL,
        DayNumberOfMonth TINYINT NOT NULL,
        DayNumberOfYear SMALLINT NOT NULL, 
        WeekNumberOfYear TINYINT NOT NULL,
        EnglishMonthName NVARCHAR(10) NOT NULL,
        MonthNumberOfYear TINYINT NOT NULL,
        CalendarQuarter TINYINT NOT NULL,
        CalendarSemester TINYINT NOT NULL,
        CalendarYear SMALLINT NOT NULL 
    )
    
    DECLARE @StartDate DATETIME
    DECLARE @EndDate DATETIME
    
    SELECT @StartDate = '2015-01-01',
           @EndDate = '2035-12-31'
    
    WHILE (@StartDate <= @EndDate)
    BEGIN
        INSERT INTO Base_DateTimeInfo 
        (
            DateKey,
            DateTime,
            [DateName],
            DayNumberOfWeek,
            DayNameOfWeek,
            DayNumberOfMonth,
            DayNumberOfYear, 
            WeekNumberOfYear,
            EnglishMonthName, 
            MonthNumberOfYear,
            CalendarQuarter,
            CalendarSemester,
            CalendarYear 
        )
        SELECT CAST(CONVERT(VARCHAR(8),@StartDate,112) AS INT) AS DateKey,
               CONVERT(VARCHAR(10), @StartDate,20) AS DateTime,
               CONVERT(VARCHAR(20), @StartDate,106) AS [DateName],
               DATEPART(DW,@StartDate) AS DayNumberOfWeek,
               DATENAME(DW,@StartDate) AS DayNameOfWeek,
               DATENAME(DD,@StartDate) AS [DayOfMonth],
               DATENAME(DY,@StartDate) AS [DayOfYear],  
               DATEPART(WW,@StartDate) AS WeekNumberOfYear,
               DATENAME(MM,@StartDate) AS EnglishMonthName,
               DATEPART(MM,@StartDate) AS MonthNumberOfYear,
               DATEPART(QQ,@StartDate) AS CalendarQuarter,
               CASE WHEN DATEPART(MM,@StartDate) BETWEEN 1 AND 6
                        THEN 1
                    ELSE 2
               END AS CalendarSemester,
               DATEPART(YY,@StartDate) AS CalendarYear 
                
        SET @StartDate = @StartDate + 1
    END
    GO
  • 相关阅读:
    (六)键盘事件
    (五)鼠标事件
    (四)WebDriver常用方法
    等价类,边界值,判定图实例
    WCF入门(三)---WCF与Web服务/Web Service
    WCF入门(二)-----实战开发
    C#中用JavaScriptSerializer和Json.Net操作json格式的文件
    C#中SaveFileDialog 和OpenFileDialog 的用法
    C#操作.csv文件Demo
    Excel操作--使用NPOI导入导出Excel为DataTable
  • 原文地址:https://www.cnblogs.com/Stephenchao/p/4335311.html
Copyright © 2011-2022 走看看