You can create subqueries using the SQL expression editor and use subqueries within subqueries--but the SQL expression only returns one value (although this could be one value per group), not a set of values. Note also that subqueries (even if this is the entire expression) must be enclosed in parens.
In CR XI, note that you cannot reference the table within the summary (corrected in CR 2008, I think), so your subquery might look like this:
(
select sum(`amount`)
from table A
where A.`ID` = table.`ID`
)
This would return the sum of amount at the ID group level.
This is the actual SQL Expression that is not working. I get a ORA-00904 "ARINVOICE"."INVOICE_DATE": Invalid identifier
(
SELECT "HIST_ARINVT_ELEMENTS"."STD_COST"
FROM "HIST_ARINVT_ELEMENTS"
WHERE "HIST_ARINVT_ELEMENTS"."ID" =
(
(SELECT MAX("HIST_ARINVT_ELEMENTS"."ID")
FROM "HIST_ARINVT_ELEMENTS"
WHERE "HIST_ARINVT_ELEMENTS"."ARINVT_ID" = ARINVT_ELEMENTS.ARINVT_ID
AND "HIST_ARINVT_ELEMENTS"."ELEMENTS_ID" = ARINVT_ELEMENTS.ELEMENTS_ID
AND "HIST_ARINVT_ELEMENTS"."ARCHIVE_DATE" < "ARINVOICE"."INVOICE_DATE")
)
)
Try the following. I added a link between the A and C tables (not sure whether this is the right linking though), removed the table reference in the summary and made a few other little changes.
(
SELECT "HIST_ARINVT_ELEMENTS"."STD_COST"
FROM "HIST_ARINVT_ELEMENTS" A
WHERE A."ID" =
(
SELECT MAX("ID")
FROM "HIST_ARINVT_ELEMENTS" A, "ARINVT_ELEMENTS" B, "ARINVOICE" C
WHERE A."ARINVT_ID" = B."ARINVT_ID" AND
A."ARINVT_ID" = C."ARINVT_ID" and
A."ELEMENTS_ID" = B."ELEMENTS_ID" AND
A."ARCHIVE_DATE" < C."INVOICE_DATE"
)
)
The tables that you reference need to be in your main report somewhere--is that the case? (Even though the SQL expression will go directly to the database to get the data).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.