Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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!
Reply With Quote
  #4 (permalink)  
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
Reply With Quote
  #5 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:30 PM.


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