...

View Full Version : SQL and Sum in ASP



Crash1hd
01-07-2005, 09:31 AM
In the following code
SQL = "Select * From CouponCode Order By FromEmail"
Set HRS = Conn.Execute(SQL)
do until HRS.EOF
Response.write HRS("CCDValue")
HRS.movenext
Loop

would give me the last value in the list of fields in a table in my db so say I had three values 10 15 and 5 it would show me 5 how can I get it to show me 30 as that is the sum of the three values I tried

SQLA = "Select Sum(CCDValue) From CouponCode"

but dont know how to get the values!

Crash1hd
01-07-2005, 10:13 AM
Never mind I figured out what I was missing

SQL = "Select Sum(CCDValue)as vol From CouponCode Where FromEmail = '" & Session("Useremail") & "'"

Response.write HRS("vol")

ghell
01-07-2005, 03:02 PM
on a sidenote, id use

Do While NOT HRS.EOF
....
Loop

i cant remember if this matters in asp, some other languages at least run untils at least once so an empty collection will still run once on eof (im really not sure about asp)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum