我正在尝试按照存储过程一次性插入全班(多个学生)的出勤率。
CREATE PROCEDURE [dbo].[usp_add_attendanceByLectureId]
-- Add the parameters for the stored procedure here
@pLectureId int,
@pUsersXml xml
AS
BEGIN
--SET NOCOUNT ON;
INSERT INTO AcademicAttendance(StudentId, LectureId, [Status])
select M.Item.value('StudentId[1]','INT') as StudentId, -- here error occured
@pLectureId as LectureId,
M.Item.value('Status','BIT') as [Status]
FROM @pUsersXml.nodes('/ArrayOfStudnts/Student') AS M(Item)
END
创建以上sp跟踪错误时出现
Msg 2389,Level 16,State 1,Procedure usp_add_attendanceByLectureId,Line 17 XQuery [value()]:'value()'需要单例(或空序列),找到类型为'xdt:untypedAtomic *'的操作数
答案 0 :(得分:1)
使用
M.Item.value('Status[1],'BIT') as [Status]
而不是
M.Item.value('Status','BIT') as [Status]