<relatedexpression>
Calculations from data contained in relational tables; can be nested in <expression>.
| Attribute | Allowed Values | Requirements | Description |
|---|---|---|---|
| name | CDATA | Required | The name of this field |
| table | %tablename | Required | The name of the table. |
| where | SQL | Optional | SQL WHERE clause; used when doing aggregate functions. |
| sort | SQL | Optional |
SQL ORDER BY clause. This automatically adds TOP 1 to the statement, which shows the top record of the specified child table. |
If outside of an <eocrepeatallrecords> tag, calculations are made on all records (aggregate functions). If aggregate functions are not used, then only first record's fields will be included in calculations.
If inside of an <eocrepeatallrecords> tag, related expression returns child records (those that have a valid foreign key relationship with record currently being bound). If related expression happens to return more than one record and it doesn't use aggregate T-SQL functions WebEOC will show an error when trying to open a display view.
Example
This example could be used both outside and inside <eocrepeatallrecords> without any issues because it uses SUM which is an aggregate T-SQL function.
<relatedexpression name="totalcost" table="deployments">Sum(cost*quantity)</relatedexpression>
To use the code in this next example inside <eocrepeatallrecords>, you must filter out only one record using the "where" attribute because you are not using any aggregate functions.
<relatedexpression name="childRecordDaysRented" table="rents" where="miles IS NULL">DATEDIFF(day, dateFrom, GETUTCDATE())</relatedexpression>