Executing a SELECT (..) GROUP BY (...) statement in ASP

I know this question is a bit daft, but humor me - I'm a bit of a novice when it comes to ASP and SQL.

I'm trying to do a SUM() and GROUP BY statement and display it using ASP. Say I have the following table

O_Id ---- OrderDate ---- OrderPrice ---- Customer
1 --------- 2008/11/12 --- 1000 ---------- Hansen
2 --------- 2008/10/23 --- 1600 ---------- Nilsen
3 --------- 2008/09/02 --- 700 ------------ Hansen
4 --------- 2008/09/03 --- 300 ------------ Hansen
5 --------- 2008/08/30 --- 2000 ---------- Jensen
6 --------- 2008/10/04 --- 100 ------------ Nilsen

And I execute the following SQL statement

"SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer"

I know that the result should look like this

Customer ---- SUM(OrderPrice)
Hansen ------- 2000
Nilsen --------- 1700
Jensen -------- 2000

But how does the ASP code that created this actually look like?

The example above is from http://www.w3schools.com/sql/sql_groupby.asp btw - A great introduction to SQL GROUP BY, but unless I have some sample code where it is actually used in ASP I'm affraid I don't know how to actually use it....

Any help would be appreciated.
Who is Participating?
YZlatConnect With a Mentor Commented:
you can display them in a table format:

Dim fld, i

  Response.Write "<table border=1>"
Response.Write "<tr>"
  Response.Write "<td>Customer</td>"
   Response.Write "<td>SUM(OrderPrice)</td>"
  Response.Write "</tr>"
For i=1 To rs.RecordCount

   If Not rs.EOF Then
    Response.Write "<tr>"
    For Each fld in rs.Fields
     Response.Write "<td>" & fld.Value & "</td>"
    Response.Write "</tr>"
   End If

  Response.Write "</table>"

you posted your question in the wrong area. Should have tried ASP
''connect the database
strConn = "Provider=SQLOLEDB;Data Source=YOURSERVERNAME;Initial Catalog=YOURDBNAME;User ID=youruser;Password=yourpwd;"
objConn = Server.CreateObject("ADODB.Connection")

SET rs = objConn.Execute("SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer")
BestAviationAuthor Commented:
I thought I did that...

That is how far I get as well - to the execution of the SQL. It's the bit that comes after I'm unsure about...

What I'm asking is how do I display the html table below using ASP.

Customer ---- SUM(OrderPrice)
Hansen ------- 2000
Nilsen --------- 1700
Jensen -------- 2000
loop through records in a recordset
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.