Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2003, 11:17 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default EASY ANSWER - sum of column in db

OK I am an idiot - someone please tell me how to get the sum of a column through asp in a db...

To explan; In excel (old days) it would be =sum(a1:a5)

I need to pull data from an sql db - get all records after filtering (done) but then display records and above it put the totals...

Example...
               A B C
              ____ ____ ____
Item A cost 10 5 5
item B cost 1 6 15

This data displays great from DB but how would I total the inidividual columns. The data manipulation is more complicated then that but if this question were answered I could get the rest... Thanks in advance to anyone answering...

Nick
 
Old August 4th, 2003, 03:24 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ALoPresto
Default

It should be something like

Code:
objCommand.CommandText = "SELECT Sum(columnName) as "varSum" FROM tableName"
Set objRS = objCommand.Execute
Response.write objRS("varSum")
That will total the column and write it. Hope this helps. Andy

Andy
AIM: LoPrestoAtWork

Trusant Technologies, LLC
 
Old August 5th, 2003, 09:32 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default

thanks!
 
Old August 5th, 2003, 01:42 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default

Does this code produce a sum of the records in the record set (filtered) or the sum of the specified column in the entire column (unfiltered)....???

Please, Thanks,
Nick
 
Old August 8th, 2003, 02:49 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ALoPresto
Default

This produces a sum of all non-null values in the column. This is because it is calculated within SQL Server, before it is passed to the recordset. HTH

Andy
AIM: LoPrestoAtWork

Trusant Technologies, LLC




Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the Sum of all the values in a column.. jhansib4u ADO.NET 1 December 1st, 2007 09:15 PM
Sum a column at the group level? srussell705 SharePoint Development 0 October 3rd, 2007 08:40 AM
Using CASE in SUM column tnzabo Oracle 1 March 26th, 2007 10:29 AM
Connecting to Pubs DB on SQL server..easy !!! tumbleweed VB Databases Basics 2 January 12th, 2005 04:40 PM
Clarifying Previous question - Sum of DB Column nlicata Classic ASP Databases 0 August 4th, 2003 01:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.