473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

You tried to execute a query that does not include the specified expression 'salesID'

9
Hi everyone
I get this error when every I try to execute a particular query in my db.
""You tried to execute a query that does not include the specified expression 'salesID' as part of an aggregated function""

This is the SQL
Expand|Select|Wrap|Line Numbers
  1. SELECT tblSalesMAIN.salesID, tblSalesMAIN.salesTime, tblSalesMAIN.salesDate, tblSalesMAIN.unitPrice, tblSalesMAIN.quantity, tblSalesMAIN.cashTendered, tblSalesMAIN.unitPriceID, [txtCashTendered]-Sum([quantity]*[unitPrice]) AS txtChange, [quantity]*[unitPrice] AS txtPrice, tblSalesMAIN.productName
  2. FROM tblSalesMAIN;
What is it that I am missing?
Jul 7 '18 #1
3 4702
Nauticalgent
100 64KB
Usually this means that you are including a field name in your SQL statement that does not exist. I assume there is infact a field named SalesID in your table tblSalesMain?
Jul 7 '18 #2
PhilOfWalton
1,430 Expert 1GB
You have 2 errors.

1) The field in your table is CashTenderd, not txtCashTenderd.

2) There is nothing to Sum. You only have a single record as SaledID is unique.

Your SQL should be
Expand|Select|Wrap|Line Numbers
  1. SELECT tblSalesMAIN.salesID, tblSalesMAIN.salesTime, tblSalesMAIN.salesDate, tblSalesMAIN.unitPrice, tblSalesMAIN.quantity, tblSalesMAIN.cashTendered, tblSalesMAIN.unitPriceID, [CashTendered]-[quantity]*[unitPrice] AS txtChange, [quantity]*[unitPrice] AS txtPrice, tblSalesMAIN.ProductName
  2. FROM tblSalesMAIN;
  3.  
Unfortunately, this is not going to achieve what I think you are wanting.
My guess is that you want a customer to buy a number of items, check the total and work out the change.

I suspect you need to consider your table structure as I think you need a table of Customers (That may not even need a name, just a CustomerID and a date so that all the sales can be "assigned" to that Customer / Date. Also a Product Table containing ProductName and probably UnitPrice.

Phil
Jul 7 '18 #3
NeoPa
32,556 Expert Mod 16PB
Whenever you use an aggregation function (Like Sum() for instance) that usage causes the SQL engine to treat your query like an aggregate query. Normally with an aggregate query you would expect a GROUP BY clause, but this isn't absolutely necessary.

So, your Sum() reference makes it an aggregate query. Each reference in the SELECT clause therefore has to be to an aggregation function or to a field included in the GROUP BY clause.

The first field is neither so the SQL engine knows you've got it wrong and lets you know about it.

What you are actually trying to achieve is anybody's guess. We certainly don't have enough information. What we can say, and what SQL has already told you, is that what you have is fundamentally wrong and why.
Jul 7 '18 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Robert Marshall | last post by:
Hi all, Hoping someone can help me with an issue I'm having. I'm using AccessXP to create a database of U.S. Census records. After keying the data in, I decided to run a query to create a...
1
by: Daveo | last post by:
Hi folks, Please see the topic below: ...
3
by: ncsthbell | last post by:
I am pulling my hair out on this! Seems like it should be easy, I just can not get it to work like I want. I know I am doing something wrong, so I hope someone can be so kind to guide me!!! I...
3
by: nitinpatel1117 | last post by:
Hi, I've got a slight issue which i'm trying to resolve and was wondering if anyone would help. Basically, I was building a web application, and while it was being built I was connecting to...
9
by: dizzydangler | last post by:
Hi, all! After receiving a lot of help from ADezzi, Msquared, and NeoPa getting my ms access 2007 db functioning, I've run into another hitch that I haven't been able to solve. The database itself...
7
by: DanicaDear | last post by:
I've tried to put together some code for a form. This code actually compiles (and I've very proud of that!) but it gives me this error when running and points to line 41 in the code below. "Run-time...
3
mikheil09
by: mikheil09 | last post by:
My Databese server is MSSQL SERVER and I connect to it with PHP's PDO class, connection is successful but when I execute query I receive question marks for all text type fields. I have "UTF-8" in...
1
by: FEILynn | last post by:
I am trying to write a query that will provide the average of 5 columns. Here is my query, but each time I try to run it I get this error: You tried to execute a query that does not include the...
1
by: swapnali143 | last post by:
How to execute query "select * from Emp where emp_id=2" in DB2
3
by: saurabh678 | last post by:
im having this same problem .. this is my query .. select title, url,sum(visit_count),microsoft from (select * from data_repository where (username='prasad'and microsoft>0 or title like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.