2

In 这个结构是对还是错,这给了我错误

SELECT TblProjectResources.UserId 
FROM TblTasks,TblProjectResources 
WHERE TblTasks.ProjectId=TblProjectResources.ProjectId 
AND TblTasks.TaskId=@TaskId AND TblProjectResources.IsRemoved=0 
AND TblProjectResources.UserId IN(
     (SELECT UserId 
      FROM TblProjectResources 
      WHERE IsRemoved=0 
      AND ProjectApproval=1 
      AND ProjectId=@ProjectId) 
     or 
     (SELECT TblAssignments.AssigneeId 
      FROM TblTasks,TblAssignments 
      WHERE TblTasks.TaskId=TblAssignments.AssignmentEntityId 
      AND TblAssignments.AssignmentEntity='Task' 
      AND TblTasks.TaskId=@TaskId) 
     or 
      (SELECT UserId FROM TblProjects WHERE ProjectId=@ProjectId)
)
4

2 回答 2

0

我认为您正在尝试像这样尝试使用TblProjectResources.UserId INtrice OR

AND (TblProjectResources.UserId IN
         (SELECT UserId 
         FROM TblProjectResources 
         WHERE IsRemoved=0 
         AND ProjectApproval=1 
         AND ProjectId=@ProjectId) 
     OR
     TblProjectResources.UserId IN 
         (SELECT TblAssignments.AssigneeId 
         FROM TblTasks,TblAssignments 
         WHERE TblTasks.TaskId=TblAssignments.AssignmentEntityId 
         AND TblAssignments.AssignmentEntity='Task' 
         AND TblTasks.TaskId=@TaskId) 
     OR
     TblProjectResources.UserId IN
      (SELECT UserId FROM TblProjects WHERE ProjectId=@ProjectId)
)
于 2012-09-15T04:28:53.247 回答
0

@hims056 答案应该适合你。作为替代方案,您可以尝试将 OR 替换为 UNION / UNION ALL。这也应该有效。

SELECT TblProjectResources.UserId 
FROM TblTasks,TblProjectResources 
WHERE TblTasks.ProjectId=TblProjectResources.ProjectId 
AND TblTasks.TaskId=@TaskId AND TblProjectResources.IsRemoved=0 
AND TblProjectResources.UserId IN(
     (SELECT UserId 
      FROM TblProjectResources 
      WHERE IsRemoved=0 
      AND ProjectApproval=1 
      AND ProjectId=@ProjectId) 
     UNION 
     (SELECT TblAssignments.AssigneeId 
      FROM TblTasks,TblAssignments 
      WHERE TblTasks.TaskId=TblAssignments.AssignmentEntityId 
      AND TblAssignments.AssignmentEntity='Task' 
      AND TblTasks.TaskId=@TaskId) 
     UNION 
      (SELECT UserId FROM TblProjects WHERE ProjectId=@ProjectId)
)
于 2012-09-15T04:31:45.003 回答