For example, the following query returns the summation for the "price" and "advance" columns in addition to the columns in the SELECT clause:
SELECT type, price, advance
FROM titles
ORDER BY type
COMPUTE SUM(price), SUM(advance) BY type
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
SELECT type, price, advance
FROM titles
ORDER BY type
COMPUTE SUM(price), SUM(advance) BY type
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<TITLE>Compute Row results</TITLE>
</HEAD>
<BODY>
<%
sql="SELECT price, advance,type FROM titles "
sql= sql & "ORDER BY type, price "
sql= sql & "COMPUTE SUM(price), SUM(advance) BY type "
sql= sql & "COMPUTE SUM(price), SUM(advance)"
set conn = Server.CreateObject("ADODB.Connection")
' Modify the connection string to reflect your
' Data Source Name (DSN).
conn.open "Pubs","sa",""
set cmd = Server.CreateObject("ADODB.Command")
cmd.CommandText = sql
set cmd.ActiveConnection = conn
set rs = Server.CreateObject("ADODB.Recordset")
set rs = cmd.Execute
%>
<table>
<%count = 1
Do Until rs Is Nothing%>
<tr>
<%For x=0 to rs.Fields.count-1%>
<td><b><%response.write rs(x).name%> </b><hr></td>
<%next%>
</tr>
<%Do While Not rs.EOF%>
<tr>
<%For x=0 to rs.Fields.count-1%>
<td><%=rs(x).value%></td>
<%next%>
</tr>
<%rs.MoveNext
Loop
Set rs = rs.NextRecordset
count = count + 1
Loop
%>
</table>
</BODY>
</HTML>
Keywords: kbcodesnippet, kbdatabase, kberrmsg, kbhowto, kbscript, KB194005