我写了这个 SP 来存储两个表中的数据,其中第二个表包含 sectionID 我想将学生分配到他们的部分
ALTER PROC [dbo].[StudentDistribution] -- '6,7,8,9,10','1,2',1,1
(
@pUserID varchar(8000),
@pSectionID varchar(8000),
@pClassID int,
@pModifiedBy int
)
as
DECLARE @Cntr int
set @Cntr = (select count(*) from split(@pUserID,','))
select sum(Capacity) from SectionsClasses where ClassID=@pClassID and SectionID in (select vItem from split(@pSectionID,','))
DECLARE FetchStudent Cursor for
select vItem from split(@pUserID,',')
DECLARE @vUserID int
DECLARE @vSecID int
DECLARE @vOut_Status int
DECLARE @vInner_Status int
Open FetchStudent
Fetch NEXT From FetchStudent into @vUserID
set @vOut_Status= @@FETCH_STATUS
WHILE @vOut_Status = 0
begin
DECLARE FetchSection Cursor for
select vItem from split(@pSectionID,',')
OPEN FetchSection
Fetch NEXT From FetchSection into @vSecID
set @vInner_Status= @@FETCH_STATUS
WHILE @vInner_Status = 0
begin
print(@vUserID)
print(@vSecID)
--IF @cntr <= 0
-- break
--else
-- set @Cntr=@Cntr-1
Fetch NEXT From FetchStudent into @vUserID
set @vOut_Status= @@FETCH_STATUS
Fetch NEXT From FetchSection into @vSecID
set @vInner_Status= @@FETCH_STATUS
END
Close FetchSection
Deallocate FetchSection
--IF @cntr <= 0
-- break
-- else
-- set @Cntr=@Cntr-1
Fetch NEXT From FetchStudent into @vUserID
END
Close FetchStudent
Deallocate FetchStudent
我需要得到这个结果
6 1
7 2
8 1
9 2
10 1
但我得到的是
6 1
7 2
9 1
10 2
谁能弄清楚问题出在哪里??