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
  • 相关阅读:
    ios属性或者变量的前缀-杂记
    xcode注释方法
    ios 不同的数据类型转化为json类型
    第一部分----HTML的基本结构与基本标签
    Git使用总结
    c#后台弹出框
    svn下载安装
    svn配置
    access 日期转换
    C# 中关于汉字与16进制转换的代码
  • 原文地址:https://www.cnblogs.com/Stephenchao/p/4335311.html
Copyright © 2011-2022 走看看