关于日历的一个超级存储过程
---函数名称:日历函数
---函数作用:产生日历--
---使用方法:select * from calendar(3,2006)
ALTER function calendar(@month int,@year int)
returns @DAY1 table(SUN char(3),MON Char(3),TUE Char(3),WED Char(3),THU Char(3),FRI Char(3),SAT Char(3))
as
begin
declare @i int
declare @j int
declare @intchk int
declare @dnum int
declare @curdate int
declare @month1 char(2)
declare @year1 char(4)
declare @date char(2)
declare @dtchk int
declare @dtval int
set @date='01'
set @month1=@month
set @year1=@year
set @dtchk=1
set @i=1
set @j=1
declare @DAY2 table(SUN char(3) default '',MON Char(3)default '',TUE Char(3)default '',WED Char(3)default '',THU Char(3)default '',FRI Char(3)default '',SAT Char(3)default '')
SELECT @curdate=DATEPART(dw, CONVERT(DATETIME,@date+'-'+@month1+'-'+@year1,103))
select @dnum=datediff(dd,convert(datetime,@date+'-'+@month1+'-'+@year1,103),dateadd(mm,1,convert(datetime,@date+'-'+@month1+'-'+@year1,103)))
while @j<=7
begin
if @curdate=@j
begin
if @j=1
begin
INSERT INTO @DAY2(sun)VALUES(@i)
set @intchk=1
set @dtchk=1
end
else if @j=2
begin
INSERT INTO @DAY2(MON)VALUES(@i)
set @intchk=2
set @dtchk=1
end
else if @j=3
begin
INSERT INTO @DAY2(TUE)VALUES(@i)
set @intchk=3
set @dtchk=1
end
else if @j=4
begin
INSERT INTO @DAY2(WED)VALUES(@i)
set @intchk=4
set @dtchk=1
end
else if @j=5
begin
INSERT INTO @DAY2(THU)VALUES(@i)
set @intchk=5
set @dtchk=1
end
else if @j=6
begin
INSERT INTO @DAY2(FRI)VALUES(@i)
set @intchk=6
set @dtchk=1
end
else if @j=7
begin
INSERT INTO @DAY2(SAT)VALUES(@i)
set @intchk=7
set @dtchk=1
end
end
set @j=@j+1
end
if @intchk=1
begin
update @day2 set mon=@i+1,tue=@i+2,wed=@i+3,thu=@i+4,fri=@i+5,sat=@i+6 where sun=1
set @dtchk=@dtchk+6
end
else if @intchk=2
begin
update @day2 set tue=@i+1,wed=@i+2,thu=@i+3,fri=@i+4,sat=@i+5 where mon=1
set @dtchk=@dtchk+5
end
else if @intchk=3
begin
update @day2 set wed=@i+1,thu=@i+2,fri=@i+3,sat=@i+4 where tue=1
set @dtchk=@dtchk+4
end
else if @intchk=4
begin
update @day2 set thu=@i+1,fri=@i+2,sat=@i+3 where wed=1
set @dtchk=@dtchk+3
end
else if @intchk=5
begin
update @day2 set fri=@i+1,sat=@i+2 where thu=1
set @dtchk=@dtchk+2
end
else if @intchk=6
begin
update @day2 set sat=@i+1 where fri=1
set @dtchk=@dtchk+1
end
else if @intchk=7
begin
Set @dtchk=@dtchk
end
insert into @day2(sun)values(@dtchk+1)
set @dtchk=@dtchk+1
if @intchk=1
begin
update @day2 set mon=@i+8,tue=@i+9,wed=@i+10,thu=@i+11,fri=@i+12,sat=@i+13 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=2
begin
update @day2 set mon=@i+7,tue=@i+8,wed=@i+9,thu=@i+10,fri=@i+11,sat=@i+12 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=3
begin
update @day2 set mon=@i+6,tue=@i+7,wed=@i+8,thu=@i+9,fri=@i+10,sat=@i+11 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=4
begin
update @day2 set mon=@i+5,tue=@i+6,wed=@i+7,thu=@i+8,fri=@i+9,sat=@i+10 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=5
begin
update @day2 set mon=@i+4,tue=@i+5,wed=@i+6,thu=@i+7,fri=@i+8,sat=@i+9 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=6
begin
update @day2 set mon=@i+3,tue=@i+4,wed=@i+5,thu=@i+6,fri=@i+7,sat=@i+8 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=7
begin
update @day2 set mon=@i+2,tue=@i+3,wed=@i+4,thu=@i+5,fri=@i+6,sat=@i+7 where sun=@dtchk
set @dtchk=@dtchk+6
end
insert into @day2(sun)values(@dtchk+1)
set @dtchk=@dtchk+1
if @intchk=1
begin
update @day2 set mon=@i+15,tue=@i+16,wed=@i+17,thu=@i+18,fri=@i+19,sat=@i+20 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=2
begin
update @day2 set mon=@i+14,tue=@i+15,wed=@i+16,thu=@i+17,fri=@i+18,sat=@i+19 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=3
begin
update @day2 set mon=@i+13,tue=@i+14,wed=@i+15,thu=@i+16,fri=@i+17,sat=@i+18 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=4
begin
update @day2 set mon=@i+12,tue=@i+13,wed=@i+14,thu=@i+15,fri=@i+16,sat=@i+17 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=5
begin
update @day2 set mon=@i+11,tue=@i+12,wed=@i+13,thu=@i+14,fri=@i+15,sat=@i+16 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=6
begin
update @day2 set mon=@i+10,tue=@i+11,wed=@i+12,thu=@i+13,fri=@i+14,sat=@i+15 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=7
begin
update @day2 set mon=@i+9,tue=@i+10,wed=@i+11,thu=@i+12,fri=@i+13,sat=@i+14 where sun=@dtchk
set @dtchk=@dtchk+6
end
insert into @day2(sun)values(@dtchk+1)
set @dtchk=@dtchk+1
if @intchk=1
begin
update @day2 set mon=@i+22,tue=@i+23,wed=@i+24,thu=@i+25,fri=@i+26,sat=@i+27 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=2
begin
update @day2 set mon=@i+21,tue=@i+22,wed=@i+23,thu=@i+24,fri=@i+25,sat=@i+26 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=3
begin
update @day2 set mon=@i+20,tue=@i+21,wed=@i+22,thu=@i+23,fri=@i+24,sat=@i+25 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=4
begin
update @day2 set mon=@i+19,tue=@i+20,wed=@i+21,thu=@i+22,fri=@i+23,sat=@i+24 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=5
begin
update @day2 set mon=@i+18,tue=@i+19,wed=@i+20,thu=@i+21,fri=@i+22,sat=@i+23 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=6
begin
update @day2 set mon=@i+17,tue=@i+18,wed=@i+19,thu=@i+20,fri=@i+21,sat=@i+22 where sun=@dtchk
set @dtchk=@dtchk+6
end
else if @intchk=7
begin
update @day2 set mon=@i+16,tue=@i+17,wed=@i+18,thu=@i+19,fri=@i+20,sat=@i+21 where sun=@dtchk
set @dtchk=@dtchk+6
end
/*set @i=@i+1
end*/
if @dtchk<>@dnum
begin
set @dtchk=@dtchk+1
insert into @day2(sun)values(@dtchk)
set @dtval=@dtchk
set @dtchk=@dtchk+1
if @dtchk<=@dnum
begin
update @day2 set mon =@dtchk where sun=@dtval
set @dtchk=@dtchk+1
end
/*insert into @dd(jk1,jk2,jk3)values(@dtchk,@dtval,@dnum)*/
if @dtchk<=@dnum
begin
update @day2 set tue=@dtchk where sun=@dtval
set @dtchk=@dtchk+1
end
if @dtchk<=@dnum
begin
update @day2 set wed=@dtchk where sun=@dtval
set @dtchk=@dtchk+1
end
if @dtchk<=@dnum
begin
update @day2 set thu=@dtchk where sun=@dtval
set @dtchk=@dtchk+1
end
if @dtchk<=@dnum
begin
update @day2 set fri=@dtchk where sun=@dtval
set @dtchk=@dtchk+1
end
if @dtchk<=@dnum
begin
update @day2 set sat=@dtchk where sun=@dtval
set @dtchk=@dtchk+1
end
if @dtchk<=@dnum
begin
insert into @day2(sun)values(@dtchk)
set @dtval=@dtchk
set @dtchk=@dtchk+1
if @dtchk<=@dnum
begin
update @day2 set mon=@dtchk where sun=@dtval
end
end
end
insert into @DAY1 select * from @DAY2
return
end
转载于:https://www.cnblogs.com/sanle/archive/2008/08/21/1273063.html
关于日历的一个超级存储过程相关推荐
- php 自定义超全局,一个超级简单的 PHP 超全局变量管理扩展
一个超级简单的 PHP 超全局变量管理扩展(自卖自夸) 介绍 SG 全称 Superglobals,它的诞生为了方便快捷操作 PHP 预定义的超全局变量,用户定义的超全局变量. 如果在非 CLI 模式 ...
- 涅槃重生的下一个超级风口:8本书助你赢在未来
导读:经济学家郎咸平发表文章<剥离货币属性,区块链涅槃重生--疫情下的区块链产业>,文中提到,未来,工业互联网和区块链的结合将是下一个超级风口.随着工业互联网连接规模的扩大,我们迫切需要通 ...
- 适合千万数据查询分页操作的一个通用存储过程
适合千万数据查询分页操作的一个通用存储过程 一.引言 最近上班比较忙,所以就很少写东西了,MongoDB系列的文章也要拖后了,没办法,工作第一,没工作就没饭吃了.今天正好 ...
- ShoeBox一个超级好用的图片切割工具
ShoeBox一个超级好用的图片切割工具 两款图片切割工具 ShoeBox:http://renderhjs.net/shoebox/ BigShear:https://www.fancynode.c ...
- 【资源分享】一个超级方便的看电子书方法推荐
[资源分享]一个超级方便的看电子书方法推荐 1.使用电子书网站 Zlibrary下载各类资源 Zlibrary全球最大数字图书馆,所有图书免费 | Tbox导航 Zlibrary 被称为 全球最大的数 ...
- Java一个超级简易的超市管理积分的系统
第一步我们首先要想清楚思路,比如我们在超市消费的时候是不是每个人都会有一张会员卡,会员卡号都是随机生成的.然后客人凭借这个卡号去消费的时候累计积分 所以第一步我们建立一个关于用户的一个Class类 p ...
- 分享一个超级好用的文本编辑器,完爆曾经的np++
1024G 嵌入式资源大放送!包括但不限于C/C++.单片机.Linux等.关注微信公众号[嵌入式大杂烩],回复1024,即可免费获取! 前言 大家好,我是ZhengN.本次给大家分享一个超级好用的. ...
- 一个简单存储过程的测试
一个简单存储过程的测试 --创建表 create table test001 (id number(4)); --表建好后,创建PROCEDURE CREATE OR REPLACE PROCEDUR ...
- 微信正在变成另外一个超级浏览器
微信账号是一个通行证.在一个用户数量庞大的体系中,腾讯构建起一个封闭式的,相对安全的一站式浏览器.腾讯站在了顶端,控制着这个封闭空间的开关,左下是用户,右下是内容提供者.目前内容的提供主要是腾讯的产品 ...
最新文章
- Ubuntu 14.04 64位上安装Valgrind 3.13.0 操作步骤
- 人群计数--Single-Image Crowd Counting via Multi-Column Convolutional Neural Network
- 《黑客与画家》读后感
- 算法每日学打卡:java语言基础题目打卡(01-10)
- 基于Kafka+Flink+Redis的电商大屏实时计算案例
- javax.servlet.ServletException: 实例化Servlet类[com.wk.web.RegisterServlet]异常
- Apache CXF入门
- 我决定不能贱卖自己(2010年11月13日志)
- 领航机器人广告段子_教育机器人广告宣传语_段子网收录最新段子
- 符号库匹配不对的原因_整理了几种离合器打滑的原因,再安装调试时可别弄错了...
- [Swift]LeetCode1051.高度检查器 | Height Checker
- typedef struct 和 struct 的区别
- iOS 新浪微博客户端Demo实践之(六) 微博评论列表页面和发评论
- 【mock】数据模板定义规范DTD 数据占位符定义规范DPD
- 程序员提高工作效率的方法
- Kalman Fuzzy Actor-Critic Learning Automaton Algorithm for the Pursuit-Evasion Differential Game
- VC++ 6.0实现视频捕捉(VFW)
- veu中高德怎么定义多个marker?
- python中的headers是什么意思_Python设置Headers
- linux 关闭桌面休眠,Linux关闭休眠和屏保模式