##### How to get a Product() (multiplication result) rather than a SUM() (addition result) using T-Sql

Get a summary aggregation of rows in T-Sql is easy thanks to the Sum operator: Select Sum(Qty) From Table Why is there no Product() aggregation operation for T-Sql? Sometimes I want the values multiplied, not added. Luckily, some one who is much smarter in math than I, observed: log(A * B) = log(A) + log(B) So, summing the log, and converting back to its exponential value will yield its product. Select CAST(EXP(SUM(LOG(Qty))) as int) as ExtendedQTY Happy Calculating! UPDATE: The above expression ......- Share This Post:
- Short Url: http://wblo.gs/cih

Posted On Wednesday, February 29, 2012 2:32 PM | Comments (1) | Filed Under [ SQL ]