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 = ‘01/01/2016‘ --开始日期 WHILE @dDate < ‘12/31/2019‘ --结束日期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 + @adddaysENDGOselect * from time_dimension总结
以上是内存溢出为你收集整理的sqlserver 生成年月周日全部内容,希望文章能够帮你解决sqlserver 生成年月周日所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)