Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > how to calculate value from one table (database)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-08-03, 07:58
zakyk zakyk is offline
Registered User
 
Join Date: Mar 2003
Posts: 32
how to calculate value from one table (database)

hi,

i have problem with this situation. i have one table which have listing item and qty for each item, so what i want to do is display all the distinct item with some parameter value and and sum the qty each item

in my table on database it's look like this

item | qty
1. Pentium 10
2. AMD Athlon 20
3. Pentium 15


then what i need to do with my asp is display like this

item | qty
1. Pentium 35
2. AMD Athlon 20

how i should code this in asp, because for display all it'work. so i'll hope you help me. it's appreciated if you give some other source code.

thanks
Reply With Quote
  #2 (permalink)  
Old 05-09-03, 00:12
Memnoch1207 Memnoch1207 is offline
Registered User
 
Join Date: Jan 2003
Location: Midwest
Posts: 138
Code:
SELECT item, SUM(qty)AS 'total' from tableName GROUP BY item HAVING SUM(qty) > 0
Reply With Quote
  #3 (permalink)  
Old 05-09-03, 04:46
zakyk zakyk is offline
Registered User
 
Join Date: Mar 2003
Posts: 32
Question

i think it works but how can we count the qty with WHERE statment

code = "001"

SELECT item, SUM(qty)AS 'total'
from tableName
GROUP BY item
HAVING SUM(qty) > 0 WHERE id_item = '"&code&"'"


it this code posssible or not

tq
Reply With Quote
  #4 (permalink)  
Old 05-09-03, 13:03
Memnoch1207 Memnoch1207 is offline
Registered User
 
Join Date: Jan 2003
Location: Midwest
Posts: 138
This works in MSSQL not sure what database your using though.
Code:
SELECT t.id, t.item, (SELECT SUM(qty) FROM tableName WHERE item = t.item) AS 'Total' FROM tableName AS t WHERE t.id = 001;
Reply With Quote
  #5 (permalink)  
Old 05-11-03, 23:15
zakyk zakyk is offline
Registered User
 
Join Date: Mar 2003
Posts: 32
Thumbs up

thank you very much your code it's work, actually im using sql server 2000..


much appreciated
tq
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

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