MSSQL 生成日期列表代码
时间:2024-01-26 23:58:01
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)
标签:生成日期列表
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python中__init__()方法详情
2023-06-05 21:22:46
![](https://img.aspxhome.com/file/2023/8/133258_0s.png)
python 检查是否为中文字符串的方法
2023-11-22 17:29:57
![](https://img.aspxhome.com/file/2023/9/63929_0s.jpg)
利用Python脚本写端口扫描器socket,python-nmap
2021-05-10 15:16:54
![](https://img.aspxhome.com/file/2023/8/110198_0s.png)
Python实现的对本地host127.0.0.1主机进行扫描端口功能示例
2021-05-13 08:43:23
![](https://img.aspxhome.com/file/2023/3/124393_0s.png)
JavaScript面试必考之实现手写Promise
2024-04-16 10:38:49
Python深入学习之闭包
2022-11-09 05:27:48
python基础入门学习笔记(Python环境搭建)
2022-01-12 20:27:48
![](https://img.aspxhome.com/file/2023/2/71502_0s.png)
Python中几种操作字符串的方法的介绍
2021-06-16 22:50:06
go语言import报错处理图文详解
2024-02-06 17:01:51
![](https://img.aspxhome.com/file/2023/0/112240_0s.png)
Python Excel数据处理之xlrd/xlwt/xlutils模块详解
2022-03-28 16:45:53
![](https://img.aspxhome.com/file/2023/9/103679_0s.png)
python实现的自动发送消息功能详解
2021-12-09 20:45:18
![](https://img.aspxhome.com/file/2023/6/127586_0s.png)
深入剖析Go语言编程中switch语句的使用
2024-02-19 16:50:45
![](https://img.aspxhome.com/file/2023/3/107353_0s.jpg)
python中import学习备忘笔记
2021-05-15 02:27:14
一文教你如何优雅处理Golang中的异常
2024-02-13 21:32:33
matlab和Excel的数据交互操作(非xlsread和xlswrite)
2022-06-16 01:00:42
![](https://img.aspxhome.com/file/2023/4/76894_0s.png)
Python爬虫制作翻译程序的示例代码
2023-08-13 06:38:35
![](https://img.aspxhome.com/file/2023/5/78725_0s.jpg)
SQL解决未能删除约束问题drop constraint
2024-01-24 20:08:09
![](https://img.aspxhome.com/file/2023/2/98042_0s.png)
通过实例解析python subprocess模块原理及用法
2022-03-26 06:21:51
利用python清除移动硬盘中的临时文件
2022-12-07 21:43:11
![](https://img.aspxhome.com/file/2023/7/67797_0s.jpg)
python 协程并发数控制
2023-09-20 01:07:10