2012-01-09 18 views
0

クラシック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> 

数量はどのように出力されますか?

答えて

5
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、私は明らかに見落としていました。 –

3

あなたのフィールドにアクセスするために

<%= rs.Fields(1) %>

あなたはまた、

のようなものにSQLクエリを変更することができ序数値を使用することができます

選択ProductIDの量として、SUM(数量)...

この列名にアクセスできるとします。

<%= rs.Fields(Quantity) %>

関連する問題