您好,登錄后才能下訂單哦!
這篇文章給大家介紹MSSQL中怎么生成日期列表,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
代碼如下: 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)
關于MSSQL中怎么生成日期列表就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。