如果 ProjectStatusType.Name 不为空,则以下 SQL 将按预期工作。因此,我放置了用“未指定”替换空值的 case 语句。我想要做的是添加一个 where 语句来显示 ProjectStatusType.Name = 'Not Specified',但没有返回任何数据,尽管数据库中有一条带有 null projectstatustype.name 的记录。请指教; 还有什么方法,或者我该如何修复 SQL 查询?
SELECT PersonResponsible.Name AS TeamLeaderName,
CASE
WHEN ProjectStatusType.Name IS NULL THEN 'Not Specified'
ELSE COALESCE(ProjectStatusType.Name, '')
END AS ProjectStatusName,
Project.ProjectTitle AS Title,
ProjectStatus.DateStatus,
Project.ProjectId,
Project.ContactName,
BusinessDivision.Name AS BusinessUnit,
BusinessUnit.Name AS WorkSection,
ProjectSubGroup.Name AS ProjectSubGroupName,
ProjectGroup.Name AS ProjectGroupName,
Project.DateRequested
FROM BusinessUnit
INNER JOIN BusinessDivision ON BusinessUnit.BusinessDivisionId = BusinessDivision.BusinessDivisionId
INNER JOIN ProjectCode ON BusinessUnit.BusinessUnitId = ProjectCode.BusinessUnitId
RIGHT OUTER JOIN Project
INNER JOIN ProjectSubGroup ON Project.ProjectSubGroupId = ProjectSubGroup.ProjectSubGroupId
INNER JOIN ProjectGroup ON ProjectSubGroup.ProjectGroupId = ProjectGroup.ProjectGroupId ON ProjectCode.ProjectCodeId = Project.ProjectCodeId
LEFT OUTER JOIN PersonResponsible ON Project.PersonResponsibleId = PersonResponsible.PersonResponsibleId FULL
OUTER JOIN ProjectStatusType
INNER JOIN ProjectStatus ON ProjectStatusType.ProjectStatusTypeId = ProjectStatus.ProjectStatusTypeId
AND ProjectStatus.ProjectStatusId IN
(SELECT MAX(ProjectStatusId) AS ProjectStatusId
FROM ProjectStatus
GROUP BY ProjectId) ON Project.ProjectId = ProjectStatus.ProjectId
WHERE ProjectStatus ProjectStatusType.Name ='Not Specified'