Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Aggregating

Author  Topic 

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-01 : 11:20:22
Hi,
We know how to use SUM() for getting the total. But how we can achieve multiplication of some values with helping a query (not assignment select or cursor)?
Is it possible to carry out with a query?

For example:
{1,3,5} -> 1*3*5 = 15

SELECT Multiplication(value)
FROM Table;

______________________

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-01 : 11:24:03
SELECT EXP(SUM(LOG(value))) FROM Table

Note that this will cause an error if you have zeros or negative numbers, as LOG() is not defined for them. LOG() and EXP() will also return float values and may not be precise.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-04-01 : 11:25:23
Refer this post
http://beyondrelational.com/blogs/madhivanan/archive/2007/11/13/simple-multiply-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-01 : 11:46:03
That's interesting, thanks.

______________________
Go to Top of Page
   

- Advertisement -