ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 10th, 2003, 11:18 AM
gxblueknight gxblueknight is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 20 gxblueknight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Adding Values in a column

I have searched the forums and can't seem to find out how to do this. I have a set of values in a column in a database, I want to add all those values up then display them, could anyone help me out.


Thanks

Reply With Quote
  #2  
Old September 10th, 2003, 11:54 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Ok what should I assume here...right nothing!

1) Build an SQL Query with the records you wish to display

2) Create a Connection Object that connects to your database.

3) Execute your SQL query using your Connection Object, this will give/create you an *implicit* Recordset object holding all the values from your SQL Query

4) Start looping using your Recordset Object displaying *at the same time* the data in a nicely formatted html <table>

5) Close and Free the Recordset and Connection Object

6) That's it!

Now...do you want a code example?
If so, then what database are you using?
What version of IIS/ASP are you using?
What's your SERVER-SIDE language your using?


Otherwise, with which part are you having problems?
a) Creating the SQL Query
b) Creating the Connection Object
c) Executing the SQL Query
d) Looping and creating a nicely formatted html <table>
e) All of the above!

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #3  
Old September 10th, 2003, 12:14 PM
gxblueknight gxblueknight is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 20 gxblueknight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I know how to do all that a-e I want to add all the values together in a single column they are numbers, I just want to add all the numbers in one column up.

Last edited by gxblueknight : September 10th, 2003 at 12:16 PM.

Reply With Quote
  #4  
Old September 10th, 2003, 12:18 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Oh..............hehe

Why not do it SQL Style with the COUNT() Keyword

Try that no?

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #5  
Old September 10th, 2003, 12:30 PM
gxblueknight gxblueknight is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 20 gxblueknight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well I would but I am not sure how to do that could you give me a code example

Thanks alot

Reply With Quote
  #6  
Old September 10th, 2003, 01:14 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Just so you'll know, this has nothing to do with your ASP page.

In fact, it's part of the SQL language.

So what you'll want is to create an SQL Query that COUNTs the total of your field in question.

Now as for an example, I'll copy/paste the books online of SQL Server:
****************************************************
Examples
A. Use COUNT and DISTINCT
This example finds the number of different cities in which authors live.

USE pubs
GO
SELECT COUNT(DISTINCT city)
FROM authors
GO

Here is the result set:

-----------
16

(1 row(s) affected)

B. Use COUNT(*)
This example finds the total number of books and titles.

USE pubs
GO
SELECT COUNT(*)
FROM titles
GO

Here is the result set:

-----------
18

(1 row(s) affected)

C. Use COUNT(*) with other aggregates
The example shows that COUNT(*) can be combined with other aggregate functions in the select list.

USE pubs
GO
SELECT COUNT(*), AVG(price)
FROM titles
WHERE advance > $1000
GO

Here is the result set:

----------- --------------------------
15 14.42

(1 row(s) affected)
****************************************************

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #7  
Old September 10th, 2003, 03:17 PM
OldJacques's Avatar
OldJacques OldJacques is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: in Orbit mostly
Posts: 148 OldJacques User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I think maybe the more suitable aggregate function of SQL would be the SUM finction which adds up all the non null values in a column, like:
sql = "SELECT SUM(Quantity) as QuantitySold, SUM(Quantity*UnitPrice) as ValueSold FROM Orders" (the second part is an example of an additional function of the SUM using a calculation)

COUNT() would give the number of Orders, but SUM() would give the numeric values added together. You could do it by getting COUNT() and AVG() and multiplying them, I suppose, but am not sure it would match perfectly, and it would mean more work anyway

Reply With Quote
  #8  
Old September 10th, 2003, 03:50 PM
gxblueknight gxblueknight is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 20 gxblueknight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yeah i used sum and it worked, thanks guys.

Reply With Quote
  #9  
Old September 10th, 2003, 06:34 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Yes OldJacques's right!

Pfffff...COUNT() c'mon, how foolish of me!

Vlince

Reply With Quote
  #10  
Old September 10th, 2003, 08:10 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
amateur

Reply With Quote
  #11  
Old September 10th, 2003, 08:52 PM
gxblueknight gxblueknight is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 20 gxblueknight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
lol

Reply With Quote
  #12  
Old September 11th, 2003, 07:12 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hehe...

Yes well aren't we all!

Thanks
Vlince

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Adding Values in a column


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT