我有七个表:
我正在尝试建立搜索以按照所选的Course_Category,TrainerResourceRequirement和UnitOfCompetency列出课程。我写了一个存储过程,如下所示:
select CourseName,ClientCourseTitle,CourseDescription,IsTheCourseDisplayedOnWeb, IsTheCourseArchived, minCandidates, maxCandidates,
Course_Category_Name =
STUFF((SELECT ', ' + CC.Course_Category_Name FROM Course_Category as CC
inner join CourseCourse_Category as CCC on CC.Course_CategoryID = CCC.Course_CategoryID
WHERE C.CourseID = CCC.CourseID and CC.Course_CategoryID = @Course_CategoryID
FOR XML PATH(''), TYPE).value('.', 'nvarchar(max)'), 1, 1, ''),
TrainerResourceName =
STUFF((SELECT ', ' + TRR.TrainerResourceName FROM TrainerResourceRequirement as TRR
inner join CourseTrainerResourceRequirement as CTRR on TRR.TrainerResourceRequirementID=CTRR.TrainerResourceRequirementID
WHERE C.CourseID = CTRR.CourseID and TRR.TrainerResourceRequirementID = @TrainerResourceRequirementID
FOR XML PATH(''), TYPE).value('.', 'nvarchar(max)'), 1, 1, ''),
UoC =
STUFF((SELECT ', ' +
UoC.UnitOfCompetencyCode + ' - ' + UoC.UnitOfCompetencyTitle as UnitofCompetencyTitle
FROM UnitOfCompetency as UoC
inner join CourseUnitOfCompetency as CUoC on UoC.UnitOfCompetencyID = CUoC.UnitOfCompetencyID
WHERE C.CourseID = CUoC.CourseID and UoC.UnitOfCompetencyID = @UnitOfCompetencyID
FOR XML PATH(''), TYPE).value('.', 'nvarchar(max)'), 1, 1, '')
FROM Course as C
order by CourseName
但是,当我尝试搜索结果时,结果是这样的:
但是结果应仅返回满足所有三个条件的那些行。
我应该如何重组查询?
提前谢谢