What Was I Thinking?

Follies & Foils of .NET Development
posts - 84 , comments - 250 , trackbacks - 0

February 2012 Entries

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 ......

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

Powered by: