+ statementBuilder.position( "'" + ou.getUid() + "'", "o.path" ) + " <> 0"; highestApprovedOrgUnitCompare = statementBuilder.position( "dao.uid", "o.path" ) + " <> 0"; "join period p on p.periodid = da.periodid " + "join organisationunit dao on dao.organisationunitid = da.organisationunitid " + "where " + statementBuilder.position( "dao.uid", "o.path" ) +" = " + pathPositionAtLevel( approvedAboveLevel ) + " " + "and '" + endDate + "' >= p.startdate and '" + endDate + "' <= p.enddate " + "and da.dataapprovallevelid = " + approvedAboveLevel.getId() + " " + "where " + statementBuilder.position( "dao.uid", "child.path" ) + " <> 0 " + "and child.organisationunitid in (select distinct sourceid from datasetsource dss join dataset ds on ds.datasetid = dss.datasetid where ds.workflowid = " + workflow.getId() + ")) " + "and not exists (select 1 from dataapproval da " + ( acceptanceRequiredForApproval ? "and da.accepted " : "" ) + ") " + "and " + statementBuilder.position( "o.uid", "dao.path" ) + " = " + pathPositionAtLevel( orgUnitLevel ) + " " + "and dao.hierarchylevel = " + approvalLevelBelowOrgUnit.getOrgUnitLevel() + " " + ( isDefaultCombo ? "" : "or exists ( select 1 from categoryoption_organisationunits c_o " + "join organisationunit o2 on o2.organisationunitid = c_o.organisationunitid " + "where c_o.categoryoptionid = cocco.categoryoptionid and " + statementBuilder.position( "o2.uid", "dao.path" ) + " between 2 and " + pathPositionAtLevel( approvalLevelBelowOrgUnit ) + ") ) " ) + ")"; "left join organisationunit oc on oc.organisationunitid = coo.organisationunitid " + "where ( coo.categoryoptionid is null or " + statementBuilder.position( "o.uid", "oc.path" ) + " <> 0 or " +