概述CREATE TABLE [dbo].[time_dimension] ( [time_id] [int] IDENTITY (1, 1) NOT NULL , [the_date] [datetime] NULL , [the_day] [nvarchar] (15) NULL , [the_month] [nvarchar] (15) NULL , [the_ye CREATE table [dbo].[time_dimension] ( [time_ID] [int] IDENTITY (1,1) NOT NulL, [the_date] [datetime] NulL, [the_day] [nvarchar] (15) NulL, [the_month] [nvarchar] (15) NulL, [the_year] [smallint] NulL, [day_of_month] [smallint] NulL, [week_of_year] [smallint] NulL, [month_of_year] [smallint] NulL, [quarter] [nvarchar] (2) NulL, [fiscal_period] [nvarchar] (20) 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 = '04/05/2013' --开始日期 WHILE @dDate < '12/31/2023' --结束日期 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 time_dimension(the_date,the_day,the_month,the_year, day_of_month, week_of_year,month_of_year,quarter) VALUES (@dDate,@WeekString,@sMonth,@iYear,@IDayOfMonth,@iWeekOfYear, @iMonthOfYear,@sQuarter) SELECT @dDate = @dDate + @adddays END GO select * from time_dimension 总结
以上是内存溢出为你收集整理的sqlserver日历表全部内容,希望文章能够帮你解决sqlserver日历表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)