SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 1st, 2004, 06:55 AM
007Dalton 007Dalton is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 29 007Dalton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old March 1st, 2004, 11:30 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
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-

Reply With Quote
  #3  
Old March 5th, 2004, 06:12 AM
007Dalton 007Dalton is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 29 007Dalton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old March 5th, 2004, 09:58 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Problem with SUM


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT