MSSQL生成日期列表

2021-05-06 18:10:35 字數 1848 閱讀 9762

-->title:generating test data

-->author:wufeng4552

-->date :2009-09-28 08:52:38 if

exists

(select

*from dbo.sysobjects where id =

object_id

(n'[dbo].[f_getdate]'

)and xtype in

(n'fn'

, n'if'

, n'tf'

))drop

function [dbo].[f_getdate] go

create

function [dbo].[f_getdate] (

@year int,--

要查詢年份

@bz bit

--@bz=0

查詢工作日

,@bz=1

查詢休息日

,@bz is null

查詢全部日期 )

returns

@re table

(date datetime

,weekday

nvarchar

(3))as

begin

declare

@tb table

(id int

,date datetime

)insert

@tb select number,

dateadd

(day

,number,

dateadd

(year

,@year-1900,

'1900-1-1'

))from

master..spt_values where

type

='p'

and number between 0 and 366

delete

from @tb where date>

dateadd

(year

,@year-1900,

'1900-12-31')if

@bz=0

insert

into @re(date,

weekday

)select date,

datename

(weekday

,date)

from @tb

where

(datepart

(weekday

,date)+

@@datefirst

-1)%7 between 1 and 5

else

if @bz=1

insert

into @re(date,

weekday

)select date,

datename

(weekday

,date)

from @tb

where

(datepart

(weekday

,date)+

@@datefirst

-1)%7 in

(0,6)

else

insert

into @re(date,

weekday

)select date,

datename

(weekday

,date)

from @tb

return

end go

select

*from dbo.[f_getdate](

'2009'

,0)

linux crontab e生成日期格式

近期公司資料庫伺服器要上雙活專案,實施顧問要收集伺服器 磁碟效能資料 io及vm的一些相關資訊,並已日期時間格式生成檔案 用crontab e增加以下內容,它的作用是每隔1個小時啟動一次iostat和vmstat,iostat的間隔為10秒,共360次,即為1個小時。以下是顧問給的指令碼,直接在終端...

MSSQL 根據年月生成日曆函式

go create function fn calendar year int,month int returns nvarchar max asbegin declare result nvarchar max enter nvarchar 8 select enter char 13 char ...

根據年,自動生成日期

引數為 year,表示年份,然後自動返回當年所有的日期,格式為 date week note 20080101 星期二 null 20080102 星期三 null 20080103 星期四 null 20081228 星期日 null 20081229 星期一 null 20081230 星期二 ...