Forums

This topic is locked

need exmple of sql to sum a column in results page

Posted 11 Jan 2002 18:13:24
1
has voted
11 Jan 2002 18:13:24  bob posted:
my results page yeilds filtered records...
one of the columns has $ values........
i want total of that column displayed?....
do i need the shopping cart ext just for this?....
Asp and sql 7 ....do i need to learn to do this in asp or sql statement?
thanks.....phil



asp form reply..............
vfarcic
Zone Manager

Spain
292 Posts Posted - 10 Jan 2002 : 09:32:43
--------------------------------------------------------------------------------
You can do it using SUM(Something) in SQL.


Edited by - gorkofor on 14 Jan 2002 01:05:32

Replies

Replied 14 Jan 2002 02:58:40
14 Jan 2002 02:58:40  bob replied:
----------1 (i like this the best)
You could just make another recordset, name it soandsoSum. Filter it
on the same variables as your other recordset. Goto advanced mode. Delete
the * after the word SELECT and put in the line

sum(whatevercolumn) as whatevercolumnSum

then leave the rest the same. On your databindings tab you should notice
the new recordset. You can expand and see the field named
whatevercolumnSum. You can drag and drop this like all other dynamic txt.

- Andrew

-------------2
Its fairly easy, but needs a little bit of hand coding....

Look at the page, and you should be able to work out where the repeat region
starts and ends, ie look for code that creates a loop that displays your
records eg While and Wend

outside that create a variable and set it to 0

eg <% myTotal = 0 %>

then inside the loop, you need to add the field from your database to
myTotal

eg <% myTotal = myTotal + rsMyRecordset.Fields.Item("total".Value %>

then below the repeat region you can display the sum total with

<% = myTotal %>


-------------3
SELECT SUM(yourtable.yourcolumn) AS newSumColumn FROM yourtable GROUP BY
your criteria HAVING something = to something else;"

This creates a new field in the recordset newSumColumn or whatever you
define it as, and you dont need to mess with creating any variables. Just
add that into the select of your recordset, dont forget the AS. AS is
basically creating an Alias name for the new field in the recordset. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>



Replied 19 Jul 2002 18:06:24
19 Jul 2002 18:06:24 Wil Turrin replied:
ANy thoughts on how to round the summed number to two decimal places?

Reply to this topic