Expressions and aggregate function in SELECT list

  • subject: expressions in select list using subExpressions and aggregate function

    This....

    (column name*column name/100)-sum(bookval)

    ... will not work, because #3:

    SQLsvr Rule:

    When aggregate functions are used in a select list, the select list can contain only:

    1. Aggregate functions.

    2. Grouping columns from a GROUP BY clause.

    3. An expression that returns the same value for every row in the result set, such as a constant.

    Is there a better way than creating an intermediate table to hold the sum and calculationResult in separate columns, then

    subtract one from the other in the next T-SQL statement?

    Thanks.

  • I think you might be able to get by with a derived table...i.e put in the aggregate function in the derived table and join it up with the original query....

    this link : http://www.sqlservercentral.com/columnists/nboyle/speed_select.asp

    gives examples of how to use derived tables..

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply