Wrox Programmer Forums
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 29th, 2003, 05:04 AM
Authorized User
Join Date: Oct 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default query


how do i create a query where i want a sum of commission of a particular person?

eg of records.
personID = 123456
salary = 3000
commission = 100 (one row in CommTable)
commission = 200 (2nd row in CommTable)

sum = 3300

i have try to create query with expression like:
Total : Sum(([salary]+[commission]))

but it gives me 3100 in a row 3200 in another row, which is not what i want.

pls advice

Old October 29th, 2003, 06:21 AM
Registered User
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to krswhy

Hi, Nono.

My suggestion is you redesign your table structure.
For example:
CommissionSecond(Currency), etc

I think Access would always return the amount "3000"+"xxx"(that you input in the second or third row and so on, because Access recognize the second/third commissions belong to another record(in your case another PersonID and another Salary)

Well, hope this would help you.

Old October 29th, 2003, 07:01 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts


You need to investigate the wonderful world of subqueries to solve this one.

You have two tables called tblSalary and tblCommission and both tables contain a field called personID.

The query would look similar to this:

SELECT tblSalary.personID, tblSalary.salary,
(SELECT SUM(tblCommission.commision)
FROM tblCommission
WHERE tblCommission.personID=tblSalary.personID) AS Commision
FROM tblSalary

This gives you the basic salary and the total commission in seperate fields in you query - you can then add them together on your form/report to show the gross pay.

P.S. Herru, I'm afraid your suggestion is a bad idea, breaking at least one of the rules of data normalisation. The main disadvantage being that a successful salesman could always earn one more lot of commission than you've provided fields in your table. nono's table structure is the correct way to go in situations like this.

Brian Skelton
Braxis Computer Services Ltd.
Old October 29th, 2003, 01:17 PM
sal sal is offline
Friend of Wrox
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts


Here is where we get into relations of known cardinality. You can not create many fields as krswhy
 suggests. This goes against rules of normalization.

A sales person is not limited to 2 commissions per period. Hopefully they will be getting more than this.

nono, you need two tables for this, Do you have two tables?
Please reply.

Old October 29th, 2003, 09:17 PM
Authorized User
Join Date: Oct 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts

yes sal,

the commission will increased as time goes.
and i have 2 tables and now the problem is solved by just grouping up the primary keys together to get the sum of commission.

thanks all.;)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
how to make a query from an existing query raport SQL Language 3 November 13th, 2006 08:59 PM
I solved insert query.now see this Update Query. amit_mande@yahoo.com VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.