我寫了這個Sp來插入/更新UserExams表,其中包含(UserID,ExamID,studentMark) 我需要爲沒有標記的學生添加新標記 並更新學生標記if它已經存在 我使用分割該函數返回表包含(ID,VITEM)更新和選擇忽略重複
我現在不哪裏是錯誤在這裏任何人可以幫助我,請 存在的錯誤,我得到的是:多部分組成的標識符「UserExams。用戶ID「不能被綁定。
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 [email protected])
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 [email protected]
--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 [email protected]
)