如何创建存储过程以获得批量中每个学生的每月出勤率? [英] how to create stored procedure to get monthly attendance percentage of each student in a batch?

查看:106
本文介绍了如何创建存储过程以获得批量中每个学生的每月出勤率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hiii每个人我都希望每个学生每月出勤。我有一个表(tbl_attendance),其中student_id,attendance_Id,出勤_Date,bacth_Id和状态字段存在。在状态字段中我存储缺席,假设,假期,离开状态(0,1,2,3)。



i希望在我选择批次,月份和年份时获得出勤率然后我将获得每月出勤率每个学生根据一个月内删除假期后的课程总数来计算。



我的存储过程是

 创建  proc  [dbo]。[Sp_GetStudentAttendancePercentage] 

@ studentId int
@ dateOfRqr date = null

as

BEGIN

s选择 distinct (( select convert decimal ,( select COUNT(a.Student_Id)* 100
来自 tbl_Attendance a 其中
a.Student_Id=@studentid Status = 1 Month_Date dateadd(mm,datediff(m, 0 @ dateOfRqr ), 0 DATEADD(d,-1,DATEADD(m, 1 ,dateadd(mm,datediff(m, 0 @ dateOfRqr ), 0 )))
)))
/(选择(DATEDIFF(d,dateadd(mm,datediff(m, 0 @ dateOfRqr ), 0 ),DATEADD(d, -1,DATEADD(m, 1 ,dateadd(mm,datediff(m, 0 @ dateOfRqr ), 0 ))))+ 1) as 百分比)
as attendenceInPercent,s.Student_Id,s.First_Name,s.Middle_Name,s.Last_Name from tbl_Attendance t inner join tbl_Student s on t.Student_Id = s.Student_Id t.Student_Id=@studentid

END

GO

解决方案

查找一个月内的工作日数的代码。

在@Date变量中传递日期



 声明  @ Date   datetime  
SET @ Date = ' 04/02/2014' / * mm / dd / yyyy * /

select DATEDIFF(DD, convert varchar 250 ),DATEADD(dd, - (DAY( @ Date ) - 1), @ Date ), 101 ), convert varchar 250 ),DATEADD(s,-1,DATEADD(mm,DATEDIFF(m, 0 ,< span class =code-sdkkeyword> @ Date )+ 1, 0 )), 101 ))+ 1



< br $>


编写一个函数来忽略日期的假期,并在你的select语句中调用它。你会得到实际的工作日。



然后计算你的学生出勤率%


hiii everyone i want to get monthly attendance of each student .i have a table(tbl_attendance) in which student_id ,attendance_Id ,Attendance _Date ,bacth_Id and Status field is exist.and in Status field i am storing absent,persent ,holiday,leaves Status by (0,1,2,3).

i want to get attendance when i select batch,month,and year then i will get monthly attendance of each student based on number of persent with total number of class after removing Holiday in a month.

my stored procedure is

CREATE proc [dbo].[Sp_GetStudentAttendancePercentage]

(@studentId int,
@dateOfRqr date=null
)
as

    BEGIN

select distinct ((select convert(decimal,(select COUNT(a.Student_Id)*100
from tbl_Attendance a where
a.Student_Id=@studentid and Status=1  and Month_Date  between dateadd(mm,datediff(m,0,@dateOfRqr),0) and DATEADD(d,-1,DATEADD(m,1,dateadd(mm,datediff(m,0,@dateOfRqr),0)))
)))
/(select (DATEDIFF(d,dateadd(mm,datediff(m,0,@dateOfRqr),0),DATEADD(d,-1,DATEADD(m,1,dateadd(mm,datediff(m,0,@dateOfRqr),0))))+1) as percentage)
) as attendenceInPercent,s.Student_Id, s.First_Name,s.Middle_Name,s.Last_Name from tbl_Attendance t inner join tbl_Student s on t.Student_Id=s.Student_Id and t.Student_Id=@studentid

    END

GO

解决方案

Code to find number of working days in a month.
pass the date in @Date variable

Declare @Date datetime
SET @Date='04/02/2014' /*mm/dd/yyyy*/

select DATEDIFF(DD,convert(varchar(250),DATEADD(dd,-(DAY(@Date)-1),@Date),101),convert(varchar(250),DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@Date)+1,0)),101))+1




Write a function to ignore holidays from the date duration and call it in youre select statement. you'll get the actual working days.

Then calculate your student attendance %


这篇关于如何创建存储过程以获得批量中每个学生的每月出勤率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆