-生成日期表
CREATE TABLE [dbo].[T_Calendar] (
[time_id] [int] IDENTITY (1, 1) NOT NULL ,
[the_date] [date] NULL ,
[the_day] [nvarchar] (15) NULL ,
[the_month] [nvarchar] (15) NULL ,
[the_year] [smallint] NULL ,
[day_of_month] [smallint] NULL ,
[holiday_type] [int] NULL
) ON [PRIMARY]
-- 再执行存储过程
DECLARE @WeekString varchar(12),
@dDate SMALLDATETIME,
@sMonth varchar(20),
@iYear smallint,
@iDayOfMonth smallint,
@iWeekOfYear smallint,
@iMonthOfYear smallint,
@sQuarter varchar(2),
@sSQL varchar(100),
@adddays int
SELECT @adddays = 1 --日期增量(可以自由设定)
SELECT @dDate = '01/01/2022 ' --开始日期
WHILE @dDate <= '12/31/2022 ' --结束日期
BEGIN
SELECT @WeekString = DATENAME (dw, @dDate)
SELECT @sMonth=DATENAME(mm,@dDate)
SELECT @iYear= DATENAME (yy, @dDate)
SELECT @iDayOfMonth=DATENAME (dd, @dDate)
SELECT @iWeekOfYear= DATENAME (week, @dDate)
SELECT @iMonthOfYear=DATEPART(month, @dDate)
SELECT @sQuarter = 'Q ' + CAST(DATENAME (quarter, @dDate)as varchar(1))
INSERT INTO T_Calendar(the_date, the_day, the_month, the_year,
day_of_month
) VALUES
(@dDate, @WeekString, @sMonth, @iYear, @iDayOfMonth)
SELECT @dDate = @dDate + @adddays
END
GO
|
|