简体   繁体   English

SQL Reporting Services-我可以对包含表达式的字段求和吗?

[英]SQL Reporting Services - Can I Sum on field that contains expression?

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? 如果我的SQL 2008报表中有一个字段是通过表达式生成的(意味着不是直接从数据集生成的),我是否应该将其SUM 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). 这将合计6个数字(因为BETWEEN语句的范围在两端都包括在内)。
You won't be able to reference the field alias 'immediately' in the WHERE clause - 您将无法在WHERE子句中“立即”引用字段别名-

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); 但是,它可以在ORDER BYGROUP BY子句中使用,也可以将查询包装在其他内容中(CTE,内联表,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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM