Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 29th, 2003, 05:04 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default query

HI

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
nono

Reply With Quote
  #2 (permalink)  
Old October 29th, 2003, 06:21 AM
Registered User
 
Join Date: Oct 2003
Location: Jakarta, , Indonesia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to krswhy
Default

Hi, Nono.

My suggestion is you redesign your table structure.
For example:
PersonID(Number)
Salary(Currency)
CommissionFirst(Currency)
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.



Herru
Reply With Quote
  #3 (permalink)  
Old October 29th, 2003, 07:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oxford, , United Kingdom.
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nono

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

Assumptions
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.
Reply With Quote
  #4 (permalink)  
Old October 29th, 2003, 01:17 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

STOP THERE!

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.



Sal
Reply With Quote
  #5 (permalink)  
Old October 29th, 2003, 09:17 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.;)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:31 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.