declare @temp int,
@temp1 int,
@temp2 int,
@temp3 int,
@temp4 int,
@temp5 int,
@modid int,
@supid int,
@sid varchar(50)
begin tran
select * from StudentSupervisor;
select @temp = count(*) from Students s where s.IsLockedOut = '0' and s.IsGraduated = '0';
select @temp1 = count(*) from staffs st where st.IsLockedOut ='0';
set @temp5 = round(@temp/@temp1,0);
WHILE (select count(*) from students s where s.IsLockedOut ='0' and s.StudentId not in (select ss.StudentId from StudentSupervisor ss where s.StudentId = ss.StudentId and ss.IsApproved = 1)) != 0
BEGIN
select top 1 @sid = s.studentid from students s, StudentSupervisor ss where s.IsLockedOut ='0' and s.StudentId not in (select s.StudentId where s.StudentId = ss.StudentId and ss.IsApproved = 1);
select top 1 @supid = st.Staffid, @modid = st.moderatorid from Staffs st where st.IsLockedOut =0 and Quota <=@temp5;
insert into StudentSupervisor
(StudentId,SupervisorId,ModeratorId,IsApproved)
values
(@sid,@supid,@modid,1)
update Staffs set quota +=1 where staffs.StaffID = @supid;
END
select * from StudentSupervisor;
ROLLBACK tran
大家好,我非常坚持这个逻辑,我确实在寻找解决方案,但在通宵工作后我什么也没得到,现在让我弄清楚我的情况,首先我想计算不在 studentsupervisor 表或 studentsupervisor 表中的学生但是被批准!= 1,然后我计算配额不超过总学生/总教职员工的人数,之后我想在他们仍然可用的时候将学生和教职员工一起抽到学生主管表中。请让我知道什么我的动态查询有问题,谢谢