|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Problem with SUM
Code:
SQL = "SELECT * FROM PurchaseCardCostCodes " SQL = SQL & " INNER JOIN PurchaseCardTransactionLog ON PurchaseCardCostCodes.costcode_id = PurchaseCardTransactionLog.costcode_id" SQL = SQL & " WHERE PurchaseCardTransactionLog.tl_date BETWEEN '"&DateOne&"' AND '"&DateTwo&"'" SQL = SQL & " AND PurchaseCardCostCodes.costcode_owner = '"&User&"'" SQL = SQL & " AND PurchaseCardCostCodes.costcode_id = '"&RadioButtonVal&"'" SQL = SQL & " SUM(PurchaseCardTransactionLog.tl_net) AS nettot" The Error: Code:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'SUM'. The SQL works fine until I add SUM ![]() |
|
#2
|
|||
|
|||
|
Post the entire finish SQL statement (What SQL is equal to)
You Sum is located in the wrong part of the statement. It is to be part of the Select portion of the statement S- |
|
#3
|
|||
|
|||
|
Right, I've made some changes.
Code:
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" The problem now is that the totals are not correct; it's printing the values of the first record, net, vat and gross and not adding the columns. |
|
#4
|
||||
|
||||
|
try something like this
Code:
SQL = "SELECT A.*, SUM(B.tl_net) AS nettot FROM PurchaseCardCostCodes A, " SQL = SQL & " INNER JOIN PurchaseCardTransactionLog B On A.costcode_id = B.costcode_id" SQL = SQL & " WHERE B.tl_date BETWEEN '" & DateOne & "' AND '" & DateTwo & "'" SQL = SQL & " AND A.costcode_owner = '" & User & "'" SQL = SQL & " AND A.costcode_id = '" & RadioButtonVal & "'" Last edited by Memnoch : March 5th, 2004 at 10:00 AM. |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Problem with SUM |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|