最近写的三个关于考勤的存储过程
前一阵做一个考勤记录的东东,自己写了三个存储过程,记录如下:
第一个:记录考勤
第二个:计算用户在某时间段内考勤记录的总时长和次数
第三个:输出考勤记录排行榜
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 张玉丰
-- Create date: 2008/8/13
-- Description: 用于输出考勤记录的排行榜
-- =============================================
ALTER PROCEDURE [dbo].[attendListTime]
(
@sDate datetime,
@eDate Datetime
)
AS
BEGIN
declare @Aid int
declare @zCount int
declare @Count int
declare @TotalTime int
declare @ACount int
declare @username nvarchar(256)
SET NOCOUNT ON;
create table #zyf_Show
(
username nvarchar(256),
Atime float,
Acount int
)

select username into #zyf_Name from dbo.aspnet_Users


set @zCount=(select count(*) from #zyf_Name)
while (@zCount>0)
begin

set @username=(select top 1 username from #zyf_Name)

set @TotalTime=0

select * into #zyf_temp from Attend
where (UserName=@username) and
(AttendTime between @sDate and @eDate) and isActive=0
set @Count=(select count(*) from #zyf_temp)
set @ACount=@Count
while (@Count>0)
begin
set @Aid=(select min(Attendid) from #zyf_temp)
set @TotalTime=@TotalTime+(select datediff(minute,(select InTime from #zyf_temp where AttendId=@Aid),(select OutTime from #zyf_temp where AttendId=@Aid)))
delete from #zyf_temp where AttendId=@Aid
set @Count=(select count(*) from #zyf_temp)
end
drop table #zyf_temp
--select @TotalTime as ok,@Aid as AID,@iTry as Try





insert into #zyf_Show(username,Atime,Acount) values(@username,@TotalTime,@ACount)
delete from #zyf_Name where username=@username
set @zCount=@zCount-1
end
select * from #zyf_Show order by Atime desc
drop table #zyf_Show
drop table #zyf_Name

END

第一个:记录考勤
1
set ANSI_NULLS ON
2
set QUOTED_IDENTIFIER ON
3
GO
4
ALTER PROCEDURE [dbo].[DS_Attend]
5
(@username nvarchar(256),
6
@action varchar(10))
7
AS
8
/*功能: 本存储过程实现成员的考勤的记录功能,及考勤时间计算功能。 */
9
/*作者:张玉丰 */
10
/*日期:2007-8-15 */
11
12
if @action='in'
13
begin
14
insert into Attend(UserName,InTime) values(@UserName,getdate())
15
update UserInfo set UIsInCenter=1 where UserName=@username
16
17
end
18
19
if @action='out'
20
begin
21
declare @startTime datetime --本次签入时间;
22
declare @oldTime float --成员累计时长;
23
set @oldTime=(select UinCenterTime from UserInfo where UserName=@username )
24
set @startTime=(select InTime from Attend where UserName=@username and IsActive=1)
25
update UserInfo set UinCenterTime=@oldTime+datediff(minute,@startTime,getdate())
26
where
27
UserName=@username
28
update Attend set OutTime=getdate(),IsActive=0 where UserName=@username and IsActive=1
29
30
31
32
update UserInfo set UIsInCenter=0 where UserName=@username
33
34
end
35
36

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

第二个:计算用户在某时间段内考勤记录的总时长和次数
1
set ANSI_NULLS ON
2
set QUOTED_IDENTIFIER ON
3
GO
4
-- =============================================
5
-- Author: 张玉丰
6
-- Create date: 2008/8/13
7
-- Description: 用于实现计算用户在某时间段内考勤记录的总时长和次数
8
-- =============================================
9
ALTER PROCEDURE [dbo].[AttendTotal]
10
(@username nvarchar(256),
11
@sDate datetime,
12
@eDate Datetime
13
)
14
15
AS
16
BEGIN
17
declare @Aid int
18
declare @Count int
19
declare @TotalTime int
20
declare @ACount int
21
--
22
--declare @iTry int
23
--set @iTry=1
24
25
set @TotalTime=0
26
select * into #zyf_temp from Attend
27
where (UserName=@username) and
28
(AttendTime between @sDate and @eDate) and isActive=0
29
set @Count=(select count(*) from #zyf_temp)
30
set @ACount=@Count
31
while (@Count>0)
32
begin
33
set @Aid=(select min(Attendid) from #zyf_temp)
34
set @TotalTime=@TotalTime+(select datediff(minute,(select InTime from #zyf_temp where AttendId=@Aid),(select OutTime from #zyf_temp where AttendId=@Aid)))
35
delete from #zyf_temp where AttendId=@Aid
36
set @Count=(select count(*) from #zyf_temp)
37
end
38
drop table #zyf_temp
39
--select @TotalTime as ok,@Aid as AID,@iTry as Try
40
select @TotalTime as Atime,@ACount as Acount
41
END
42
43

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

第三个:输出考勤记录排行榜






































































【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· 因为Apifox不支持离线,我果断选择了Apipost!