我写了这个 Sp 来插入/更新包含 (UserID,ExamID,studentMark) 的 UserExams 表我需要为没有标记的学生添加新标记,如果它已经存在则更新学生标记我使用返回表包含的拆分函数 (ID ,v项目)
我现在不知道这里的错误在哪里,任何人都可以帮助我,我得到的错误是:无法绑定多部分标识符“UserExams.UserID”。
ALTER PROC [dbo].[InsertUserMarks]
(
@pSemesterID int,
@pCourseID int,
@pExamID int,
@pClassID int,
@pUserID varchar(8000),
@pMarks varchar(8000)
)
as
--save the values of MaxMark To check if there is any Mark higher than the full mark if so then stop execution
DECLARE @vTestMaxMark decimal(5,2)
SET @vTestMaxMark = (select ExamMark from Exams where ExamID=@pExamID)
IF EXISTS (select 'true' from Split(@pMarks,',') WHERE vItem>@vTestMaxMark)
begin
print('Operation cannot complete; there are one or more Mark ABOVE the Max value')
return
end
update UserExams
Set StudentMark=MA.vItem
from split(@pUserID,',') us
inner join split(@pMarks,',') ma on us.ID = ma.id
where UserExams.UserID=US.vItem
and UserExams.ExamID=@pExamID
--Insert
insert into UserExams
select us.vItem,1,ma.vItem,system_user,getdate(),null,null from
split(@pUserID,',') us
inner join split(@pMarks,',') ma on us.ID = ma.id
WHERE NOT EXISTS (
SELECT 'True'
FROM split(@pUserID,',') us
inner join split(@pMarks,',') ma on us.ID = ma.id
where UserExams.UserID=US.vItem
and UserExams.ExamID=@pExamID
)