Creating Sub-Queries in Crystal Reports Using a SQL Expression
| The information in the article applies to |
| Synopsis |
| Solution |
(
SELECT MAX(shipping_dt)
FROM SalesTable TABLE_Sales_01
WHERE order_no = "SalesTable"."order_no"
)
There are two crucial elements for this code to work properly. First you need to encompass the code with an open parenthesis and a closed parenthesis; this enables the database to know that this is a sub-query inside the main SQL that Crystal passes. Second, an alias is created in the FROM statement for the data (shipping_dt in the SELECT and order_no in the WHERE) that this sub-query is analyzing. The table of the field from the main SQL ("SalesTable"."order_no") that is used to link the sub-query to the main SQL is not referenced in the FROM statement.
* One Crystal SQL Expression sub-query can only result in one expression
**The above SQL code is SQL Sever specific
*** Using sub-queries in Crystal SQL Expressions is not supported by Business Objects
Have a question for our trainers?
Click here to send your questions!
