我有以下TSQL Select语句
select s.StudentID, s.LastName, s.FirstName ,o.CourseID, c.CourseTitle, o.Semester, s.Feedback_Status
from Students as s join StudentEnrollments as se
on s.StudentID = se.StudentID
join OfferedCourses as o
on o.SectionID = se.SectionID
join Courses as c
on c.CourseID = o.CourseID
where s.StudentID = 4 and o.Semester='spring'
返回以下内容
StudentID LastName FirstName CourseID CourseTitle Semester Feedback_Status
----------- ---------------------------------------------------------------------------
4 Fakhouri Fadi 1 MathI Spring 0
4 Fakhouri Fadi 5 MathII Spring 0
我写了一个更新查询,将特定行的feedback_status字段更改为1
update s
set s.Feedback_Status = 1
from Students as s join StudentEnrollments as se
on s.StudentID = se.StudentID
join OfferedCourses as o
on o.SectionID = se.SectionID
join Courses as c
on c.CourseID = o.CourseID
where s.StudentID = 4 and o.Semester='spring' and c.CourseID=1
我得到的结果是
StudentID LastName FirstName CourseID CourseTitle Semester Feedback_Status
----------- ---------------------------------------------------------------------------
4 Fakhouri Fadi 1 MathI Spring 1
4 Fakhouri Fadi 5 MathII Spring 1
feedback_status字段在两行上都得到更新,不明白为什么。非常感谢您的帮助
我无法移动feeback_status,该字段是一个布尔值,告诉我用户是否输入了反馈。该应用程序通过输入studentID然后linq查询(通过数据网格)显示学生注册的所有课程。数据网格中的每一行都有一个按钮,用于添加反馈。我需要使用fedback_status作为标志来记录它。
我查看了表格并解决了问题,我需要将feedback_status字段移动到 StudentEnrollments表,那样我有一个重复的studentID和fedback_status的
由于
答案 0 :(得分:1)
您正在更新Feedback_Status
表中的Students
,我假设您只有StudentID
的一条记录.4。当您进行更新时,设置该记录的状态到1然后我认为该记录在您的结果中出现两次。
您可以将Feedback_Status
列移到另一个表格,可能是Courses
?