ProjectStatusType.Name が null でない場合、次の SQL は期待どおりに機能します。したがって、null 値を「指定なし」に置き換える case ステートメントを入れます。私がやろうとしているのは、ProjectStatusType.Name = 'Not Specified' を表示する where ステートメントを追加することですが、データベースには 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'