This query does the job, but I am sure it can be improved. Any tips would be much appreciated :)
SELECT RIH.ItemName, RI.FieldAnswer, RIH.IsConditional
FROM ReportItemHeader AS RIH
INNER JOIN ReportItem AS RI
ON RIH.ItemID = RI.ItemID
AND RIH.ReportID = RI.ReportID
WHERE RIH.ReportID = 2080258
AND RIH.SectionNumber = 3
EXCEPT
SELECT RIH.ItemName, RI.FieldAnswer, RIH.IsConditional
FROM ReportItemHeader AS RIH
INNER JOIN ReportItem AS RI
ON RIH.ItemID = RI.ItemID
AND RIH.ReportID = RI.ReportID
WHERE RIH.ReportID = 2080258
AND RIH.SectionNumber = 3
AND RIH.IsConditional = 1
AND RI.FieldAnswer = ''
You can remove the second SELECT
if you adapt the first WHERE
clause as follows:
SELECT RIH.ItemName, RI.FieldAnswer, RIH.IsConditional
FROM ReportItemHeader AS RIH
INNER JOIN ReportItem AS RI
ON RIH.ItemID = RI.ItemID AND RIH.ReportID = RI.ReportID
WHERE RIH.ReportID = 2080258 AND RIH.SectionNumber = 3
AND NOT(RIH.IsConditional = 1 AND RI.FieldAnswer = '')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.