If I have a field in my SQL 2008 report that is generated via expression (meaning not directly from a dataset) should I be able to SUM
it? Can I reference the field in a subsequent expression somehow - like by referencing the box name?
Your question isn't completely clear... but I'll take a stab at it.
Do you mean something like this:
SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_That_Has_Infinite_Rows
WHERE rowId BETWEEN 3 AND 8
This will sum 6 numbers (because the range of a BETWEEN
statement is inclusive on both ends).
You won't be able to reference the field alias 'immediately' in the WHERE
clause -
SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_With_One_Row
WHERE randomSum > 5 -- throws error, field 'does not exist'
However, it will be available in ORDER BY
and GROUP BY
clauses, and also if you wrap the query in something else (CTE, inline table, etx);
SELECT SUM(GET_RANDOM_NUMBER()) as randomSum
FROM Table_With_Thousand_Rows
GROUP BY randomSum -- although this won't have any apparent effect here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.