本文介绍了如何创建存储过程以获得批量中每个学生的每月出勤率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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 解决方案 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 BEGINselect distinct ((select convert(decimal,(select COUNT(a.Student_Id)*100from tbl_Attendance a wherea.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 ENDGO 解决方案 这篇关于如何创建存储过程以获得批量中每个学生的每月出勤率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 21:21