在经典ASP页面上输出SQL查询

问题描述:

我在经典asp页面上运行下列查询。在经典ASP页面上输出SQL查询

sSQL = "Select ProductID, SUM(Quantity) FROM OrderDetails Where CAST(orderDate AS DATE) Between '"&sStartDate&"' And '"&sEndDate&"' GROUP BY ProductID" 
Set rs = Server.CreateObject("ADODB.RecordSet") 
rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText 

<tr> 
<td> 
<%Response.Write(rs.Fields("ProductID"))%> 
</td> 
<td> 
What is the code to get the sum of the quantity here? 
</td> 

如何输出数量?

sSQL = "Select ProductID, SUM(Quantity) as TotalQuantity FROM OrderDetails Where CAST(orderDate AS DATE) Between '"&sStartDate&"' And '"&sEndDate&"' GROUP BY ProductID" 
Set rs = Server.CreateObject("ADODB.RecordSet") 
rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText 

<tr> 
<td> 
<%Response.Write(rs.Fields("ProductID"))%> 
</td> 
<td> 
<%= rs.Fields("TotalQuantity") %> 
</td> 
+0

谢谢Jinesh,我完全忽略了明显的。 – 2012-01-09 11:35:52

可以使用序号值来访问你的领域

<%= rs.Fields(1) %>

你也可以改变你的SQL查询来像

选择的ProductID,SUM(数量)由于数量...

然后您可以访问此列名称

<%= rs.Fields(Quantity) %>