当前位置:首页 > 开发 > 数据库 > 正文

获取去年一年的年月日的SQL

发表于: 2015-04-04   作者:18289753290   来源:转载   浏览:
摘要: 1)获取去年一年的年月日的SQL: SELECT     CONVERT (      VARCHAR (7),      dateadd(mm ,- 12, getdate()),      120    
1)获取去年一年的年月日的SQL:
SELECT
    CONVERT (
     VARCHAR (7),
     dateadd(mm ,- 12, getdate()),
     120
    ) sj,YEAR(dateadd(mm ,- 12, getdate())) year,MONTH(dateadd(mm ,- 12, getdate())) month
   UNION ALL
    SELECT
     CONVERT (
      VARCHAR (7),
      dateadd(mm ,- 11, getdate()),
      120
     ) sj,YEAR(dateadd(mm ,- 11, getdate())) year,MONTH(dateadd(mm ,- 11, getdate())) month
    UNION ALL
     SELECT
      CONVERT (
       VARCHAR (7),
       dateadd(mm ,- 10, getdate()),
       120
      ) sj,YEAR(dateadd(mm ,- 10, getdate())) year,MONTH(dateadd(mm ,- 10, getdate())) month
     UNION ALL
      SELECT
       CONVERT (
        VARCHAR (7),
        dateadd(mm ,- 9, getdate()),
        120
       ) sj,YEAR(dateadd(mm ,- 9, getdate())) year,MONTH(dateadd(mm ,- 9, getdate())) month
      UNION ALL
       SELECT
        CONVERT (
         VARCHAR (7),
         dateadd(mm ,- 8, getdate()),
         120
        ) sj,YEAR(dateadd(mm ,- 8, getdate())) year,MONTH(dateadd(mm ,- 8, getdate())) month
       UNION ALL
        SELECT
         CONVERT (
          VARCHAR (7),
          dateadd(mm ,- 7, getdate()),
          120
         ) sj,YEAR(dateadd(mm ,- 7, getdate())) year,MONTH(dateadd(mm ,- 7, getdate())) month
        UNION ALL
         SELECT
          CONVERT (
           VARCHAR (7),
           dateadd(mm ,- 6, getdate()),
           120
          ) sj,YEAR(dateadd(mm ,- 6, getdate())) year,MONTH(dateadd(mm ,- 6, getdate())) month
         UNION ALL
          SELECT
           CONVERT (
            VARCHAR (7),
            dateadd(mm ,- 5, getdate()),
            120
           ) sj,YEAR(dateadd(mm ,- 5, getdate())) year,MONTH(dateadd(mm ,- 5, getdate())) month
          UNION ALL
           SELECT
            CONVERT (
             VARCHAR (7),
             dateadd(mm ,- 4, getdate()),
             120
            ) sj,YEAR(dateadd(mm ,- 4, getdate())) year,MONTH(dateadd(mm ,- 4, getdate())) month
           UNION ALL
            SELECT
             CONVERT (
              VARCHAR (7),
              dateadd(mm ,- 3, getdate()),
              120
             ) sj,YEAR(dateadd(mm ,- 3, getdate())) year,MONTH(dateadd(mm ,- 3, getdate())) month
            UNION ALL
             SELECT
              CONVERT (
               VARCHAR (7),
               dateadd(mm ,- 2, getdate()),
               120
              ) sj,YEAR(dateadd(mm ,- 2, getdate())) year,MONTH(dateadd(mm ,- 2, getdate())) month
             UNION ALL
              SELECT
               CONVERT (
                VARCHAR (7),
                dateadd(mm ,- 1, getdate()),
                120
               ) sj,YEAR(dateadd(mm ,- 1, getdate())) year,MONTH(dateadd(mm ,- 1, getdate())) month

获取去年一年的年月日的SQL

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号