Monday, April 29, 2024

SQL Server find current year - Previous Year

  SELECT        TimePeriod

          FROM            (SELECT        YEAR(GETDATE()) AS TimePeriod

          UNION

          SELECT        YEAR(GETDATE()) - 1 AS Expr1

          UNION

          SELECT        YEAR(GETDATE()) - 2 AS Expr1

          UNION

          SELECT        YEAR(GETDATE()) - 3 AS Expr1

          UNION

          SELECT        YEAR(GETDATE()) - 4 AS Expr1) AS t

          ORDER BY TimePeriod DESC

No comments:

Post a Comment