473,388 Members | 1,346 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,388 software developers and data experts.

Q: How to create query expression that calculates based on table values

I need help understanding how to get a query to lookup an employee's
sales (tblSales) and calculate and expression (Commission) based on a
CommissionRate (tblCommissionSchedule) that corresponds to that
employee's sales.

table (example record):
tblSales
---------------
1.lngEmployeeID (1)
curSales ($20,000)

tblCommissionSchedule
---------------------
1. curSalaryStart ($0)
curSalaryEnd ($50,000)
decCommmissionRate (0.10)

2. curSalaryStart ($51,000)
curSalaryEnd ($75,000)
decCommissionRate (0.15)

Query should return:
lngEmployeeID (1)
curSales ($20,000)
Commission ($2,000)

Any help is greatly appreciated!
Nov 12 '05 #1
5 3704
tom
here's a start...

SELECT
s.lngEmployeeID, s.CurSales, s.curSales * c.decCommissionRate As Commission
FROM
tblSales as s,
tblCommissionSchedule as c
WHERE
s.CurSales Between c.curSalaryStart And c.curSalaryEnd

-td

so*********@hotmail.com (John) wrote in message news:<90**************************@posting.google. com>...
I need help understanding how to get a query to lookup an employee's
sales (tblSales) and calculate and expression (Commission) based on a
CommissionRate (tblCommissionSchedule) that corresponds to that
employee's sales.

table (example record):
tblSales
---------------
1.lngEmployeeID (1)
curSales ($20,000)

tblCommissionSchedule
---------------------
1. curSalaryStart ($0)
curSalaryEnd ($50,000)
decCommmissionRate (0.10)

2. curSalaryStart ($51,000)
curSalaryEnd ($75,000)
decCommissionRate (0.15)

Query should return:
lngEmployeeID (1)
curSales ($20,000)
Commission ($2,000)

Any help is greatly appreciated!

Nov 12 '05 #2
Thanks Tom....that hit the spot!

-john

to*@nuws.com (tom) wrote in message news:<c1**************************@posting.google. com>...
here's a start...

SELECT
s.lngEmployeeID, s.CurSales, s.curSales * c.decCommissionRate As Commission
FROM
tblSales as s,
tblCommissionSchedule as c
WHERE
s.CurSales Between c.curSalaryStart And c.curSalaryEnd

-td

so*********@hotmail.com (John) wrote in message news:<90**************************@posting.google. com>...
I need help understanding how to get a query to lookup an employee's
sales (tblSales) and calculate and expression (Commission) based on a
CommissionRate (tblCommissionSchedule) that corresponds to that
employee's sales.

table (example record):
tblSales
---------------
1.lngEmployeeID (1)
curSales ($20,000)

tblCommissionSchedule
---------------------
1. curSalaryStart ($0)
curSalaryEnd ($50,000)
decCommmissionRate (0.10)

2. curSalaryStart ($51,000)
curSalaryEnd ($75,000)
decCommissionRate (0.15)

Query should return:
lngEmployeeID (1)
curSales ($20,000)
Commission ($2,000)

Any help is greatly appreciated!

Nov 12 '05 #3
A follow-up question:

How would I add a second expression that caculates a "paycheck total",
which would be equal to the sum of Commission (an expression) and
tblSales.curSales?

When I created the expression:
Paycheck: sum([curSales]+[Commission])

I get this error:
You tried to execute a query that does not include the specified
expression <name> as part of an aggregate function. (Error 3122)

I feel like this is yet another simple question where the answer is
just not coming to me...
to*@nuws.com (tom) wrote in message news:<c1**************************@posting.google. com>...
here's a start...

SELECT
s.lngEmployeeID, s.CurSales, s.curSales * c.decCommissionRate As Commission
FROM
tblSales as s,
tblCommissionSchedule as c
WHERE
s.CurSales Between c.curSalaryStart And c.curSalaryEnd

-td

so*********@hotmail.com (John) wrote in message news:<90**************************@posting.google. com>...
I need help understanding how to get a query to lookup an employee's
sales (tblSales) and calculate and expression (Commission) based on a
CommissionRate (tblCommissionSchedule) that corresponds to that
employee's sales.

table (example record):
tblSales
---------------
1.lngEmployeeID (1)
curSales ($20,000)

tblCommissionSchedule
---------------------
1. curSalaryStart ($0)
curSalaryEnd ($50,000)
decCommmissionRate (0.10)

2. curSalaryStart ($51,000)
curSalaryEnd ($75,000)
decCommissionRate (0.15)

Query should return:
lngEmployeeID (1)
curSales ($20,000)
Commission ($2,000)

Any help is greatly appreciated!

Nov 12 '05 #4
BAM! There's the answer...
Paycheck: [Commission] + [curSales]

Although, Tom, I'm curious why you renamed the tables in your SQL to
"s" and "c." Can you or anyone else enlighten me?

-john

to*@nuws.com (tom) wrote in message news:<c1**************************@posting.google. com>...
here's a start...

SELECT
s.lngEmployeeID, s.CurSales, s.curSales * c.decCommissionRate As Commission
FROM
tblSales as s,
tblCommissionSchedule as c
WHERE
s.CurSales Between c.curSalaryStart And c.curSalaryEnd

-td

so*********@hotmail.com (John) wrote in message news:<90**************************@posting.google. com>...
I need help understanding how to get a query to lookup an employee's
sales (tblSales) and calculate and expression (Commission) based on a
CommissionRate (tblCommissionSchedule) that corresponds to that
employee's sales.

table (example record):
tblSales
---------------
1.lngEmployeeID (1)
curSales ($20,000)

tblCommissionSchedule
---------------------
1. curSalaryStart ($0)
curSalaryEnd ($50,000)
decCommmissionRate (0.10)

2. curSalaryStart ($51,000)
curSalaryEnd ($75,000)
decCommissionRate (0.15)

Query should return:
lngEmployeeID (1)
curSales ($20,000)
Commission ($2,000)

Any help is greatly appreciated!

Nov 12 '05 #5
so*********@hotmail.com (John) wrote in message news:<90**************************@posting.google. com>...
BAM! There's the answer...
Paycheck: [Commission] + [curSales]

Although, Tom, I'm curious why you renamed the tables in your SQL to
"s" and "c." Can you or anyone else enlighten me?

-john


just makes the SQL easier to write and maybe understand. Much easier
to alias a long name than to retype it several times...
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
18
by: PC Datasheet | last post by:
An Access user saw my name in a newsgroup and sent me a request for help on a project. As part of the project, a list of the dates in a month was needed. For anyone needing a list of dates in a...
2
by: igor.barbaric | last post by:
Hello! I have created a very simple query like this: SELECT Tasks.Name, DurationHrs(,) AS Duration FROM Tasks INNER JOIN Log ON Tasks.TaskID=Log.TaskID; The above query works fine....
4
by: Macroman | last post by:
MS Access XP, running on Win XP, Processor 2.4Ghz , 512Mb RAM, 40Gb Hard drive Table 1 has 167,000 records and contains the following fields tblone_custID tblone_easting tblone_northing ...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
6
by: sstidham | last post by:
I have a query which calculates the data from two table and then yields the number of points based on various calculations for each category. Essentially we are trying to rank our Agents based on...
9
by: Sinner | last post by:
Hi, I have a field name 'USER' in tableMAIN. How do I replace the user names with corresponding user names. I can do that in xl using vlookup but now I'm trying to find a way to do that in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.