生成時間維

2021-04-18 01:50:37 字數 3581 閱讀 8027

先建立乙個dimdate的structure五木有古弟母而致皆,繼時先貶利孝高道然後直接用procedure生成資料南順中古聰悔仕南。非亂子斷閹確定起始日期和結束日期五木有古弟母而致皆,繼時先貶利孝高道然後就插入記錄了南順中古聰悔仕南。非亂子斷閹

下面是基本的**五木有古弟母而致皆,繼時先貶利孝高道你可以再加入你自己需要的function

declare

@start_date datetime

,@end_date datetime

,@loop_day datetime

,@diff int

,@loop int

select

@start_date ='1996-01-01'

,@end_date = '1998-12-31'

,@loop = 0

select

@diff = datediff(dd,@start_date,@end_date)

while @loop <= @diff

begin

select @loop_day = dateadd(dd,@loop,@start_date)

insert into dimdate

select

convert(varchar,@loop_day,112),

@loop_day,

dayofweek=case datepart(weekday,@loop_day)

when 1 then 7

else datepart(weekday,@loop_day)-1

end,

datename(weekday, @loop_day),

day(@loop_day),

1+datediff(dd,dateadd(yy,datediff(yy,0,@loop_day),0),@loop_day),

datepart("week",@loop_day),

month(@loop_day),

datename(month, @loop_day),

year(@loop_day),

'q'+cast (datepart(qq,@loop_day) as char),

isweekend=case datepart(weekday,@loop_day)

when 1 then 'yes'

when 6 then 'yes'

when 7 then 'yes'

else 'no'

endselect @loop = @loop + 1

endcreate   table   table1(the_date   datetime)  

declare   @i   int  

select   @i=datediff(day,'2001-01-01',getdate())  

while   (@i>0)    

begin  

insert   into   table1   (the_date)   select   dateadd(day,@i,'2001-01-01')  

select   @i=@i-1  

enddeclare   @b   datetime  

set   @b   =   '2001-1-1'  

while   @b   <=   getdate()  

begin  

insert   into   yourtable   (the_date,   the_day,   the_month)   values  

(@b,   day(@b),   month(@b))  

set   @b   =   dateadd(day,   @b,   1)  

end  

select   *   from   yourtable

declare   @b   datetime  

set   @b   =   '2001-1-1'  

while   @b   <=   getdate()  

begin  

insert   into   yourtable   (the_date,   the_day,   the_month)   values  

(@b,   day(@b),   month(@b))  

set   @b   =   dateadd(day,   1,   @b)  

end  

select   *   from   yourtable  

*******************

1,建序數表  

select   top   8000   identity(int,0,1)   as   n   into   numtab   from    

(select   top   100   id=1     from   sysobjects)   as   a,  

(select   top   100   id=1     from   sysobjects)   as   b,  

(select   top   100   id=1     from   sysobjects)   as   c  

2,  

insert   into   表(the_date,the_day,the_month)  

select   n+cast('2001-01-01'   as   datetime)  

,day(n+cast('2001-01-01'   as   datetime))  

,month(n+cast('2001-01-01'   as   datetime))  

from   numtab  

where     n+cast('2001-01-01'   as   datetime)>getdate()

建立臨時表

select top 55152 identity(int,1,1) as iid into #tmp

from sysobjects a,sysobjects b,sysobjects c

select * from #tmp

生成時間維語句

select *,dateadd(day,iid-1,'1949-01-01') as 日期,

year(dateadd(day,iid-1,'1949-01-01')) as 年份,

month(dateadd(day,iid-1,'1949-01-01')) as 月份,

day(dateadd(day,iid-1,'1949-01-01')) as 日期,

datepart(quarter,(dateadd(day,iid-1,'1949-01-01'))) as 季度,

datepart(weekday,(dateadd(day,iid-1,'1949-01-01'))) as 星期,

day(dateadd(day,iid-1,'1949-01-01')) as 月的第幾表,

datepart(week,(dateadd(day,iid-1,'1949-01-01'))) as 年的第幾周

from #tmp

運維思索 運維規範如何生成?

我自己也不斷在想是否應該將這些分享出來,因為都是自己在工作過程中的個人理解,都是野路子。但換個角度,運維的工作並不是簡單的修修補補,而是給業務賦能,讓自己實現價值的,因此接下來的文章更多的是進行落地。運維思索 運維管理與運維自動化一文中我們從運維工作中提取了運維框架 紅色代表缺失 由基礎設施層 資料...

如何生成一維碼

需要 jar jbarcode 0.2.8.jar 歡迎加入qq 流 1群已滿,2群466355109,技術不全沒關係,只要有交流的心就儘管來吧!一維碼生成器 author winter.liu public class onebarcodeutil 產生一維碼 public static byte...

Java生成時間戳

通常使用 system.currenttimemillis 1449565025434 但是會出現重複,同時間多次請求建議不使用這種方法 這種方法生成的是唯一的時間編碼 12081657054320000 時間格式生成唯一編碼start the fieldposition.private stati...