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 2000 Forums
 Transact-SQL (2000)
 Challenge #2

Author  Topic 

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-11-20 : 12:16:50
table t
------
v
------
11.07
... ...
25.22
32.68

Get multiplication: 11.07*...*...*25.22*32.68
1. Number of rows is unknown.
2. Don't mind possible overflow.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-20 : 12:25:58
Stoad, perhaps if you explained it better then people might bite on this. As of now, I don't have any idea what you are asking.

Tara
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-11-20 : 12:36:03
set @result = 1

select @result=@result * v from t

select @result



- Jeff
Go to Top of Page

Granick
Starting Member

46 Posts

Posted - 2003-11-20 : 12:44:52
That is a really simple solution. Way shorter than what I was trying out.

Shannon
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-11-20 : 13:11:15
Ahhh.. of course, Jeff, it's OK!

But how about one single query without using
any variables and temp tables?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-11-20 : 13:38:44
if i recall .... there is a formula out there using logorithms or something like that where you can do this ..... where was that ?!

- Jeff
Go to Top of Page

Granick
Starting Member

46 Posts

Posted - 2003-11-20 : 13:42:39
Jeff you are right, I did a little searching, and found that the following works.

SELECT EXP(SUM(LOG(v))) FROM t

I wish I could take credit for it, but sadly, I found it using google.

Shannon
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-11-20 : 13:58:14
Haha!!.. OK, that's done! :)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-11-20 : 14:50:37
I knew I read this somewhere before:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=26615

that's definitely a very interesting mathematical fact ....

- Jeff
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-11-20 : 15:32:59
Nothing new under the moon.. aahhh..
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-20 : 15:34:59
So the point was multiplication of a column? I had seen Jeff's solution on mssqlserver.com as one of the tips a while back. I never knew that you could do that.

Tara
Go to Top of Page
   

- Advertisement -