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
 SQL Server Development (2000)
 Calculate total.

Author  Topic 

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-12-06 : 05:46:03
Hi,

I'm tryin' to write a query which calculates the total sum of a column based on a certain string, tried with sum but it doesn't return the result i want.

my table looks a little like this.

id indent
userno varchar
price decimal

id userno price
1 28780116 0.31
2 28780116 3.67
3 28800808 1.21

and my asp :

sql = "select price, sum(price) as totalsum from usage where userno='28780116' group by price"
set rs = Conn.execute(SQL)


response.write rs("totalsum")

rs("totalsum") should equal 3.98

but somehow this doesn't happen, rs("totalsum") only contains 0.31.

i've search through the forum but hasn't found any query which i could use.

Any help would be very much appreciated.

Thanks.

Best regards
Taz.

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2004-12-06 : 06:56:30
quote:

...group by price


Hm...

--Frank
http://www.insidesql.de
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-12-06 : 08:27:29
the "GROUP BY" clause, groups 'likeminded' (identical) values...in this case you are asking for records to be grouped on the prices....but you have no duplicates(based on the price column anyway)!!!!....

In effect in this case, you are asking for detail AND SUMMARY data to be displayed for each record.

I suspect that you have 2 records being returned in your resultset.

"select sum(price) as totalsum from usage where userno='28780116'"
will achieve your aim.
Go to Top of Page

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-12-06 : 09:00:09
Thanks Andrew, but of course...

How embarressing hehe

Best regards
Taz
Go to Top of Page
   

- Advertisement -