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

Writing Query with criteria

Hello Everyone,

We are a dev team very new to Access, and so far we have gotten
excellent support from this group. We have a question about writing a
query. Here is the situation:

We have a query that pulls data from a detail table and displays the
total for 1 column.

DetailTable:
ProjectID (not unique)
EffectiveDate
TotalSalary

Query:
ProjectID (can have multiple records for the same ID)
EffectiveDate
SumofTotalSalary

That works. Simple enough!

Now, what we want is a query (may be we need another query or modify
this one), that:

A = Calculate days from effective date (Date minus EffectiveDate)
B = Multiply A with TotalSalary for each record
Show single record for each Project ID with the total of all Bs for
this ProjectID

Here is the query we have for the first part:
SELECT DISTINCTROW tblPersonnel.ProjectID, tblPersonnel.EffDate,
Sum(tblPersonnel.TotalSalary) AS [Sum Of TotalSalary]
FROM tblPersonnel
GROUP BY tblPersonnel.ProjectID, tblPersonnel.EffDate;
Here is the result we get:

"ProjectID","EffDate","Sum Of TotalSalary"
"J2006",8/1/2005 0:00:00,$115320.00
"P001",9/9/2006 0:00:00,$95020.00
"P007",1/1/2007 0:00:00,$82620.00
"P102",1/1/2007 0:00:00,$69300.00
"P110",1/1/2008 0:00:00,$55800.00

Thanks in advance for looking into this. You all are awsome.

Puneet.

Aug 2 '06 #1
3 4135
ac*******@gmail.com wrote in
news:11**********************@i42g2000cwa.googlegr oups.com:
Hello Everyone,

Now, what we want is a query (may be we need another query or
modify this one), that:

A = Calculate days from effective date (Date minus
EffectiveDate) B = Multiply A with TotalSalary for each record
Show single record for each Project ID with the total of all
Bs for this ProjectID

Here is the query we have for the first part:
SELECT DISTINCTROW tblPersonnel.ProjectID,
tblPersonnel.EffDate, Sum(tblPersonnel.TotalSalary) AS [Sum Of
TotalSalary] FROM tblPersonnel
GROUP BY tblPersonnel.ProjectID, tblPersonnel.EffDate;
Here is the result we get:

"ProjectID","EffDate","Sum Of TotalSalary"
"J2006",8/1/2005 0:00:00,$115320.00
"P001",9/9/2006 0:00:00,$95020.00
"P007",1/1/2007 0:00:00,$82620.00
"P102",1/1/2007 0:00:00,$69300.00
"P110",1/1/2008 0:00:00,$55800.00

Thanks in advance for looking into this. You all are awsome.
For the first step, you use the datediff() function.
datediff("d", effdate, date()). the "d" tells the function that
you want the difference in days. You could get months, weeks or
even seconds.

Note that since some of your dates are future, you'll want to
figure out some logic to exclude those dates else you'll have
negative days, and negative amounts..

An issue is the period of Salary. if it's by year, you will need
to divide by 365.

Then you insert all these expressions in the sum() function
above.

something like
sum(tblPersonnel.TotalSalary * iif(effdate date(), 0, datediff
( "d", effdate, date()) / 365) As [Sum Of Total Salary]

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 3 '06 #2
Hi Bob,

That worked like a charm. Thanks.

However, I hvae a little complication to add, and I will explain by
example:
tblPersonnel:
ProjectID, ResourceID, BaseSalary, EffDate, PercentEffort, EffSalary,
Fringe, TotalSalary
P001, R990, 50000, 1/1/2006, 100, 50000, 10000, 60000
P001, R991, 60000, 1/1/2006, 100, 70000, 13000, 83000
P001, R990, 50000, 7/1/2006, 50, 25000, 10000, 35000

As you see, what is happening in this table via forms is --
In the beginning, R990 and R991 are at 100% effort on this project. So
their BaseSalary and EffSalary are same. Add some Fringe to it, and you
get the TotalSalary.

Now, effective 7/1/2006, R990 is changed from 100% to 50% effort.
Hence, the BaseSalary for this resource is down to 25000 and the
TotalSalary is 35000.

(I am creating a separate record every time the % Effort for the
resource is changed)

What I need to calculate is the total burn till date on the project for
all resources over the life of the project. So, if today is 8/3/2006,
it should come up to:
(60000/365) * DateDiff("d", 1/1/2006, 6/30/2006) +
(83000/365) * DateDiff("d", 1/1/2006, 8/3/2006) +
(35000/365) * DateDiff("d", 7/1/2006, 8/3/2006)

I just cant seem to figure out how to write this in the query. so for
example, in the first row of my sample calc above, how do I know if the
resource has another record from 7/1/2006, so only do 1/1 to 6/30....

Thanks again,
Puneet.
Bob Quintal wrote:
ac*******@gmail.com wrote in
news:11**********************@i42g2000cwa.googlegr oups.com:
Hello Everyone,

Now, what we want is a query (may be we need another query or
modify this one), that:

A = Calculate days from effective date (Date minus
EffectiveDate) B = Multiply A with TotalSalary for each record
Show single record for each Project ID with the total of all
Bs for this ProjectID

Here is the query we have for the first part:
SELECT DISTINCTROW tblPersonnel.ProjectID,
tblPersonnel.EffDate, Sum(tblPersonnel.TotalSalary) AS [Sum Of
TotalSalary] FROM tblPersonnel
GROUP BY tblPersonnel.ProjectID, tblPersonnel.EffDate;
Here is the result we get:

"ProjectID","EffDate","Sum Of TotalSalary"
"J2006",8/1/2005 0:00:00,$115320.00
"P001",9/9/2006 0:00:00,$95020.00
"P007",1/1/2007 0:00:00,$82620.00
"P102",1/1/2007 0:00:00,$69300.00
"P110",1/1/2008 0:00:00,$55800.00

Thanks in advance for looking into this. You all are awsome.
For the first step, you use the datediff() function.
datediff("d", effdate, date()). the "d" tells the function that
you want the difference in days. You could get months, weeks or
even seconds.

Note that since some of your dates are future, you'll want to
figure out some logic to exclude those dates else you'll have
negative days, and negative amounts..

An issue is the period of Salary. if it's by year, you will need
to divide by 365.

Then you insert all these expressions in the sum() function
above.

something like
sum(tblPersonnel.TotalSalary * iif(effdate date(), 0, datediff
( "d", effdate, date()) / 365) As [Sum Of Total Salary]

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com
Aug 3 '06 #3
ac*******@gmail.com wrote in
news:11**********************@p79g2000cwp.googlegr oups.com:
Hi Bob,

That worked like a charm. Thanks.

However, I hvae a little complication to add, and I will
explain by example:
tblPersonnel:
ProjectID, ResourceID, BaseSalary, EffDate, PercentEffort,
EffSalary, Fringe, TotalSalary
P001, R990, 50000, 1/1/2006, 100, 50000, 10000, 60000
P001, R991, 60000, 1/1/2006, 100, 70000, 13000, 83000
P001, R990, 50000, 7/1/2006, 50, 25000, 10000, 35000

As you see, what is happening in this table via forms is --
In the beginning, R990 and R991 are at 100% effort on this
project. So their BaseSalary and EffSalary are same. Add some
Fringe to it, and you get the TotalSalary.

Now, effective 7/1/2006, R990 is changed from 100% to 50%
effort. Hence, the BaseSalary for this resource is down to
25000 and the TotalSalary is 35000.

(I am creating a separate record every time the % Effort for
the resource is changed)

What I need to calculate is the total burn till date on the
project for all resources over the life of the project. So, if
today is 8/3/2006, it should come up to:
(60000/365) * DateDiff("d", 1/1/2006, 6/30/2006) +
(83000/365) * DateDiff("d", 1/1/2006, 8/3/2006) +
(35000/365) * DateDiff("d", 7/1/2006, 8/3/2006)

I just cant seem to figure out how to write this in the query.
so for example, in the first row of my sample calc above, how
do I know if the resource has another record from 7/1/2006, so
only do 1/1 to 6/30....

Thanks again,
Puneet.
So what you need is a second date in the table. Instead of
EffDate, you need dteEffFrom and dteEffThru

Then you do another Iif to determine if dteEffThru is less than
today's date, and use that instead of today's date.
Then you sum the results.

-
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 3 '06 #4

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

Similar topics

3
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
6
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3...
5
by: SuffrinMick | last post by:
Hello - I'm a newbie to coding! I'm working on an access 2000 database which has three tables: tblContacts - A list of customer contacts. tblOrgTypes - A list of organisational types....
2
by: Matthew | last post by:
Hey , I have built a query which takes values from unbounded fields on a form, and it all works except for one thing. I have a few fields in my query that are dates. I also have a start and...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
8
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
0
by: MLH | last post by:
I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the selections made in a number of criteria choices on a form, a field on the form will have string...
3
by: MLH | last post by:
Am repeating question with different subject heading, perhaps stating more clearly my problem... I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the...
3
by: Thorben Grosser | last post by:
Hello Newsgroup, I am doing some archive database and therefore got one table indexing every folder and one table storing which rack belongs to which department, eg: table folders :...
6
by: jmarcrum | last post by:
Hi! I have created a Union Query in ACCESS 2003, that combines 130 records from one query (Extra Foreman Radios) and 250 records from another query (Forman Main Radios). I have created a...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.