diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java index 8789dd8711b..16ff1804e26 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java @@ -673,17 +673,14 @@ private String getSelectForInsert( ? "(select ${selectExpression} ${dataClause})${closingParentheses} as ${uid}" : "${selectExpression}${closingParentheses} as ${uid}"; + String s = getClosingParentheses(selectExpression); return replaceQualify( sqlTemplate, Map.of( - "selectExpression", - selectExpression, - "dataClause", - dataFilterClause, - "closingParentheses", - getClosingParentheses(selectExpression), - "uid", - quote(dataElement.getUid()))); + "selectExpression", selectExpression, + "dataClause", dataFilterClause, + "closingParentheses", s, + "uid", quote(dataElement.getUid()))); } /**