Calculating fields for Access

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Chris Nebinger (anonymous_at_discussions.microsoft.com)
Date: 05/04/04


Date: Tue, 4 May 2004 09:44:10 -0700

Well, it looks like your database design is a little off.
Instead of having a Pay_Code_1 and Pay_Code_2 field, you
should just have a Pay_Code field, and then have 2 records
for two entrys.

But, to answer your question, we can use a Union Query to
change the data to a more normalized format:

Select ID,Pay_Code_1 as Pay_Code, Pay_Code_1Hour as
PAY_Code_Hour From TableName
UNION
Select ID,Pay_Code_2 as Pay_Code, Pay_Code_2Hour as
PAY_Code_Hour From TableName

Save that query, and now use that the basis of your SUM
query.

Chris Nebinger

>-----Original Message-----
>Hi all,
> I am trying to calculate two fields. I have six fields
in
>query window...
>
>ID, PAY_CODE_1, PAY_CODE_1HOUR, PAY_CODE_2, PAY_CODE_2HOUR
>
>PAY_CODE_1 and PAY_CODE_2 include pay codes such as
>REG,OVT,SICK,DBL...ets..
>
>I am trying to SUM the pay codes based on hours. Just to
>make it clear I need PAY_CODE_1 summarized by
>PAY_CODE_1HOURS and PAY_CODE_2 by PAY_CODE_2HOURS.
>
>I group by PAY_CODE_1 and I use SUM in the Total field
for
>PAY_CODE_1_HOUR. If I run the query I receive the total
>hours.
>
>Now the problem....
>There is no problem when I execute the queries
>independently. When I try to run one query containing
>PAY_CODE_1 and PAY_CODE_2 I don't receive the same
results
>because in my opinion Access confuses the fields having
>some indentical codes(such as REG and OVT on both fields).
>
>I need to have all codes summarized by hours, no matter
in
>one or two queries. Since I get the results by running
two
>separate queries is there a way (or code) to add up the
>matching fields from both queries plus the ones that are
>not matching to have one complete field with all total
>codes which later be execute in a report. Or a way to
>differentiate the fields so Access can run the SUM..
>
>Sorry for the long post but I can't figure this out..
>thank you
>
>galin
>.
>



Relevant Pages

  • Re: Problem
    ... Is there any way to create a query like i could use sub queries in the query ... "Tom Ellison" wrote: ... > The Need column you have is not the sum of all the needed quantities. ...
    (microsoft.public.access.queries)
  • Re: Problem
    ... Is there any way to create a query like i could use sub queries in the query ... "Tom Ellison" wrote: ... > The Need column you have is not the sum of all the needed quantities. ...
    (microsoft.public.access.queries)
  • Calculating fields for Access
    ... I am trying to SUM the pay codes based on hours. ... If I run the query I receive the total ... There is no problem when I execute the queries ...
    (microsoft.public.access.gettingstarted)
  • Calculating fields for Access
    ... I am aware now that my database is a little off. ... How can I make Access sum up ... >>I am trying to SUM the pay codes based on hours. ... >>one or two queries. ...
    (microsoft.public.access.gettingstarted)
  • Re: Outer Join?
    ... Look up UNION query to combine the two tabls into one. ... Union queries can only be built in SQL view. ... SELECT Who, When, Cases, [Sum of Score] ...
    (microsoft.public.access.queries)