This topic is locked

SQL SUM in a WHERE and Group By

3/5/2004 8:56:11 AM
ASPRunnerPro General questions
0
007Dalton author

I'm not getting the totals for columns; net_total, gross_amount_total and vat_amount_total. Instead, ASP is printing out the 1st record net, vat and gross records rather than a total for each of these columns.
The SQL is saying Select these fields between 2 dates WHERE user is e.g. 'user12' AND the costcode is e.g. '1'

SQL_TOTALS = "SELECT pccc.costcode_id,

pccc.costcode_owner, pctl.tl_date, SUM(pctl.tl_net) AS

net_total"
SQL_TOTALS = SQL_TOTALS & ",SUM(pctl.tl_vat_amount) AS

vat_amount_total"
SQL_TOTALS = SQL_TOTALS & ", SUM(pctl.tl_gross_amount)

AS gross_amount_total "
SQL_TOTALS = SQL_TOTALS & "FROM

PurchaseCardCostCodes pccc INNER JOIN

PurchaseCardTransactionLog pctl ON pccc.costcode_id =

pctl.costcode_id"
SQL_TOTALS = SQL_TOTALS & " WHERE pctl.tl_date

BETWEEN '"&DateOne&"' AND '"&DateTwo&"'"

SQL_TOTALS = SQL_TOTALS & " AND pccc.costcode_owner

= '"&User&"'"
SQL_TOTALS = SQL_TOTALS & " AND pccc.costcode_id

= '"&RadioButtonVal&"'"
SQL_TOTALS = SQL_TOTALS & "GROUP BY pccc.costcode_id,

pccc.costcode_owner, pctl.tl_date"
Sergey Kornilov admin 3/10/2004

This code is not easy to follow. Could you post resulting SQL query text along with your tables structure?