Displaying SUM, AVG or COUNT results

Results 1 to 2 of 2

Thread: Displaying SUM, AVG or COUNT results

  1. #1
    Join Date
    Dec 1969

    Default Displaying SUM, AVG or COUNT results

    Forgive the newbie question but I just can&#039;t find an answer anywhere. I&#039;m using an SQL query like "SELECT SUM(rating) from Reviews" and don&#039;t know how to display the results once i&#039;ve got the recordset. The only way I can think of how to do it is to loop through using a for/next loop like:<BR><BR>for each x in RSReviewRecordset.Fields<BR> Response.Write x.Value<BR>next<BR><BR>That seems clunky - is there an easier way to display results out of a recordset from SQL Queries using SUM, COUNT(*) or AVG?

  2. #2
    Join Date
    Dec 1969

    Default You have to assign an alias

    SELECT SUM(Amount) as TotalAmount FROM TheTable<BR><BR>In your asp page you use<BR><BR>Response.Write RecordSet ("TotalAmount")<BR><BR>You could also use the ordinal position (starting at 0 )<BR><BR>SELECT CustomerID, SUM(Amount) as TotalAmount FROM Orders<BR>GROUP BY CustomerID<BR><BR>Response.Write RecordSet(1) returns the totalamount<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts