sqlserver 生成年月周日

sqlserver 生成年月周日,第1张

概述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 = ‘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 生成年月周日所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1176739.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存