Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL sum method error

Status
Not open for further replies.

zann

Programmer
Nov 7, 2002
7
0
0
ZA
Hi all

I am trying to use a query in a vb app, that uses ADO. I have successfully created and executed the query in ms access. But when i try run the query from my VB code I get an ODBC error. The problem is (at least I think) the sum method. I am not sure if it is supported by ODBC and ADO.

Here is the SQL statement:
SELECT Seller, Sum(quantity*price) FROM transaction
WHERE AuctionName ='ttt' AND AuctionDate = '11/18/2002'
GROUP BY Seller
ORDER BY Sum(quantity*price) DESC;

If i take the Sum part out the query works but I obviously need it so is there any way of using the Sum method or another alternative.

thanx in advance.
 
I haven't tested it but how about:

Code:
SELECT Seller, Sum(quantity*price) AS Cost FROM transaction
WHERE AuctionName ='ttt' AND AuctionDate = '11/18/2002'
GROUP BY Seller
ORDER BY Cost DESC;
[pc2]
 
Dates have to be offset with #, not '.

Try that and see what happens.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
ADO does not have a problem with this syntax, but as pointed out by Jeremy Access needs # around the date fields.

SELECT Seller, Sum(quantity*price) AS Cost FROM transaction
WHERE AuctionName ='ttt' AND AuctionDate = '11/18/2002'
GROUP BY Seller
ORDER BY Sum(quantity*price) DESC;

I don't believe Access will accept "Cost" in the Order by clause.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top