Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-2008, 04:18 PM
Bob Quintal
 
Posts: n/a
Re: Finding the date of last pay rise

"John" <John@nospam.infovis.co.uk> wrote in
news:u6p1qNIUIHA.5264@TK2MSFTNGP02.phx.gbl:

> Hi
>
> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff
> start at a rate and their jobs from that day onwards have that
> rate. Then they get a raise and this is reflected in their
> subsequent jobs and so on.
>
> I need to extract from the above table a result set which has
> Staff ID, Max of the their Rates (i.e. current salary of the
> staff), First Job's date on that Max Rate (i.e. date of last pay
> rise). How can I achieve this using queries?
>
> Thanks
>
> Regards
>

You need to use a subquery to first return the max() value related
to the employee ID, then use that to get the other relevand data.

SELECT M.[Staff ID], M.[Job Rate], M.[Job Start Date]
FROM Jobs Alias M
WHERE M.[Job Rate] =
(SELECT max([Job Rate]) as CurrentRate
FROM Jobs Alias S
WHERE M.[Staff ID] = S.[Staff ID])
AND M.[Staff ID] = [S. Job ID]

You can build the subquery first, test it, and then paste the SQL
into the criteria row of the Main Query.

But Is your way the right way? What if an employee gets a pay
decrease? ( it does happen)

Would it not be better to get the most recent Job date and lookup
the salary?

--
Bob Quintal

PA is y I've altered my email address.

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

Reply With Quote
  #2 (permalink)  
Old 01-06-2008, 04:18 PM
Bob Quintal
 
Posts: n/a
Re: Finding the date of last pay rise

"John" <John@nospam.infovis.co.uk> wrote in
news:u6p1qNIUIHA.5264@TK2MSFTNGP02.phx.gbl:

> Hi
>
> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff
> start at a rate and their jobs from that day onwards have that
> rate. Then they get a raise and this is reflected in their
> subsequent jobs and so on.
>
> I need to extract from the above table a result set which has
> Staff ID, Max of the their Rates (i.e. current salary of the
> staff), First Job's date on that Max Rate (i.e. date of last pay
> rise). How can I achieve this using queries?
>
> Thanks
>
> Regards
>

You need to use a subquery to first return the max() value related
to the employee ID, then use that to get the other relevand data.

SELECT M.[Staff ID], M.[Job Rate], M.[Job Start Date]
FROM Jobs Alias M
WHERE M.[Job Rate] =
(SELECT max([Job Rate]) as CurrentRate
FROM Jobs Alias S
WHERE M.[Staff ID] = S.[Staff ID])
AND M.[Staff ID] = [S. Job ID]

You can build the subquery first, test it, and then paste the SQL
into the criteria row of the Main Query.

But Is your way the right way? What if an employee gets a pay
decrease? ( it does happen)

Would it not be better to get the most recent Job date and lookup
the salary?

--
Bob Quintal

PA is y I've altered my email address.

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

Reply With Quote
  #3 (permalink)  
Old 01-06-2008, 04:44 PM
John
 
Posts: n/a
Finding the date of last pay rise

Hi

I have a Jobs table with Staff ID, Job Rate and Job Date. Staff start at a
rate and their jobs from that day onwards have that rate. Then they get a
raise and this is reflected in their subsequent jobs and so on.

I need to extract from the above table a result set which has Staff ID, Max
of the their Rates (i.e. current salary of the staff), First Job's date on
that Max Rate (i.e. date of last pay rise). How can I achieve this using
queries?

Thanks

Regards


Reply With Quote
  #4 (permalink)  
Old 01-06-2008, 05:13 PM
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
 
Posts: n/a
RE: Finding the date of last pay rise

Use subqueries to return the MIN Job Date for the MAX Job Rate for the
current Staff ID, e.g.

SELECT [Staff ID], MAX([Job Rate]) AS [Current Rate],
(SELECT MIN([Job Date])
FROM Jobs AS J2
WHERE J2.[Staff ID] = J1.[Staff ID]
AND J2.[Job Rate] =
(SELECT MAX([Job Rate])
FROM Jobs AS J3
WHERE J3.[Staff ID] = J1.[Staff ID]))
AS [Date of Last Pay Rise]
FROM Jobs AS J1;

Ken Sheridan
Stafford, England

"John" wrote:

> Hi
>
> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff start at a
> rate and their jobs from that day onwards have that rate. Then they get a
> raise and this is reflected in their subsequent jobs and so on.
>
> I need to extract from the above table a result set which has Staff ID, Max
> of the their Rates (i.e. current salary of the staff), First Job's date on
> that Max Rate (i.e. date of last pay rise). How can I achieve this using
> queries?
>
> Thanks
>
> Regards
>
>
>


Reply With Quote
  #5 (permalink)  
Old 01-06-2008, 05:13 PM
=?Utf-8?B?S2VuIFNoZXJpZGFu?=
 
Posts: n/a
RE: Finding the date of last pay rise

Use subqueries to return the MIN Job Date for the MAX Job Rate for the
current Staff ID, e.g.

SELECT [Staff ID], MAX([Job Rate]) AS [Current Rate],
(SELECT MIN([Job Date])
FROM Jobs AS J2
WHERE J2.[Staff ID] = J1.[Staff ID]
AND J2.[Job Rate] =
(SELECT MAX([Job Rate])
FROM Jobs AS J3
WHERE J3.[Staff ID] = J1.[Staff ID]))
AS [Date of Last Pay Rise]
FROM Jobs AS J1;

Ken Sheridan
Stafford, England

"John" wrote:

> Hi
>
> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff start at a
> rate and their jobs from that day onwards have that rate. Then they get a
> raise and this is reflected in their subsequent jobs and so on.
>
> I need to extract from the above table a result set which has Staff ID, Max
> of the their Rates (i.e. current salary of the staff), First Job's date on
> that Max Rate (i.e. date of last pay rise). How can I achieve this using
> queries?
>
> Thanks
>
> Regards
>
>
>


Reply With Quote
  #6 (permalink)  
Old 01-06-2008, 05:13 PM
John
 
Posts: n/a
Re: Finding the date of last pay rise

Hi Bob

Thanks for that.

No staff do not get pay decrease, they get fined or fired. :)

Regards

"Bob Quintal" <rquintal@sPAmpatico.ca> wrote in message
news:Xns9A1D7B7653698BQuintal@66.150.105.47...
> "John" <John@nospam.infovis.co.uk> wrote in
> news:u6p1qNIUIHA.5264@TK2MSFTNGP02.phx.gbl:
>
>> Hi
>>
>> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff
>> start at a rate and their jobs from that day onwards have that
>> rate. Then they get a raise and this is reflected in their
>> subsequent jobs and so on.
>>
>> I need to extract from the above table a result set which has
>> Staff ID, Max of the their Rates (i.e. current salary of the
>> staff), First Job's date on that Max Rate (i.e. date of last pay
>> rise). How can I achieve this using queries?
>>
>> Thanks
>>
>> Regards
>>

> You need to use a subquery to first return the max() value related
> to the employee ID, then use that to get the other relevand data.
>
> SELECT M.[Staff ID], M.[Job Rate], M.[Job Start Date]
> FROM Jobs Alias M
> WHERE M.[Job Rate] =
> (SELECT max([Job Rate]) as CurrentRate
> FROM Jobs Alias S
> WHERE M.[Staff ID] = S.[Staff ID])
> AND M.[Staff ID] = [S. Job ID]
>
> You can build the subquery first, test it, and then paste the SQL
> into the criteria row of the Main Query.
>
> But Is your way the right way? What if an employee gets a pay
> decrease? ( it does happen)
>
> Would it not be better to get the most recent Job date and lookup
> the salary?
>
> --
> Bob Quintal
>
> PA is y I've altered my email address.
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



Reply With Quote
  #7 (permalink)  
Old 01-06-2008, 05:13 PM
John
 
Posts: n/a
Re: Finding the date of last pay rise

Hi Bob

Thanks for that.

No staff do not get pay decrease, they get fined or fired. :)

Regards

"Bob Quintal" <rquintal@sPAmpatico.ca> wrote in message
news:Xns9A1D7B7653698BQuintal@66.150.105.47...
> "John" <John@nospam.infovis.co.uk> wrote in
> news:u6p1qNIUIHA.5264@TK2MSFTNGP02.phx.gbl:
>
>> Hi
>>
>> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff
>> start at a rate and their jobs from that day onwards have that
>> rate. Then they get a raise and this is reflected in their
>> subsequent jobs and so on.
>>
>> I need to extract from the above table a result set which has
>> Staff ID, Max of the their Rates (i.e. current salary of the
>> staff), First Job's date on that Max Rate (i.e. date of last pay
>> rise). How can I achieve this using queries?
>>
>> Thanks
>>
>> Regards
>>

> You need to use a subquery to first return the max() value related
> to the employee ID, then use that to get the other relevand data.
>
> SELECT M.[Staff ID], M.[Job Rate], M.[Job Start Date]
> FROM Jobs Alias M
> WHERE M.[Job Rate] =
> (SELECT max([Job Rate]) as CurrentRate
> FROM Jobs Alias S
> WHERE M.[Staff ID] = S.[Staff ID])
> AND M.[Staff ID] = [S. Job ID]
>
> You can build the subquery first, test it, and then paste the SQL
> into the criteria row of the Main Query.
>
> But Is your way the right way? What if an employee gets a pay
> decrease? ( it does happen)
>
> Would it not be better to get the most recent Job date and lookup
> the salary?
>
> --
> Bob Quintal
>
> PA is y I've altered my email address.
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



Reply With Quote
  #8 (permalink)  
Old 01-06-2008, 05:20 PM
John
 
Posts: n/a
Re: Finding the date of last pay rise

Hi Bob

Looks like I have not understood the sql well. It is not returning any rows.
Here is what I tried.

SELECT M.[Staff ID], M.[Rate], M.[Date]
FROM [Jobs] as M
WHERE M.[Rate] =
(SELECT max([Rate]) as CurrentRate
FROM [Jobs] As S
WHERE M.[Staff ID] = S.[Staff ID])
AND M.[Job ID] = S.[Job ID]

Any ideas?

Thanks

Regards


"Bob Quintal" <rquintal@sPAmpatico.ca> wrote in message
news:Xns9A1D7B7653698BQuintal@66.150.105.47...
> "John" <John@nospam.infovis.co.uk> wrote in
> news:u6p1qNIUIHA.5264@TK2MSFTNGP02.phx.gbl:
>
>> Hi
>>
>> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff
>> start at a rate and their jobs from that day onwards have that
>> rate. Then they get a raise and this is reflected in their
>> subsequent jobs and so on.
>>
>> I need to extract from the above table a result set which has
>> Staff ID, Max of the their Rates (i.e. current salary of the
>> staff), First Job's date on that Max Rate (i.e. date of last pay
>> rise). How can I achieve this using queries?
>>
>> Thanks
>>
>> Regards
>>

> You need to use a subquery to first return the max() value related
> to the employee ID, then use that to get the other relevand data.
>
> SELECT M.[Staff ID], M.[Job Rate], M.[Job Start Date]
> FROM Jobs Alias M
> WHERE M.[Job Rate] =
> (SELECT max([Job Rate]) as CurrentRate
> FROM Jobs Alias S
> WHERE M.[Staff ID] = S.[Staff ID])
> AND M.[Staff ID] = [S. Job ID]
>
> You can build the subquery first, test it, and then paste the SQL
> into the criteria row of the Main Query.
>
> But Is your way the right way? What if an employee gets a pay
> decrease? ( it does happen)
>
> Would it not be better to get the most recent Job date and lookup
> the salary?
>
> --
> Bob Quintal
>
> PA is y I've altered my email address.
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



Reply With Quote
  #9 (permalink)  
Old 01-06-2008, 05:20 PM
John
 
Posts: n/a
Re: Finding the date of last pay rise

Hi Bob

Looks like I have not understood the sql well. It is not returning any rows.
Here is what I tried.

SELECT M.[Staff ID], M.[Rate], M.[Date]
FROM [Jobs] as M
WHERE M.[Rate] =
(SELECT max([Rate]) as CurrentRate
FROM [Jobs] As S
WHERE M.[Staff ID] = S.[Staff ID])
AND M.[Job ID] = S.[Job ID]

Any ideas?

Thanks

Regards


"Bob Quintal" <rquintal@sPAmpatico.ca> wrote in message
news:Xns9A1D7B7653698BQuintal@66.150.105.47...
> "John" <John@nospam.infovis.co.uk> wrote in
> news:u6p1qNIUIHA.5264@TK2MSFTNGP02.phx.gbl:
>
>> Hi
>>
>> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff
>> start at a rate and their jobs from that day onwards have that
>> rate. Then they get a raise and this is reflected in their
>> subsequent jobs and so on.
>>
>> I need to extract from the above table a result set which has
>> Staff ID, Max of the their Rates (i.e. current salary of the
>> staff), First Job's date on that Max Rate (i.e. date of last pay
>> rise). How can I achieve this using queries?
>>
>> Thanks
>>
>> Regards
>>

> You need to use a subquery to first return the max() value related
> to the employee ID, then use that to get the other relevand data.
>
> SELECT M.[Staff ID], M.[Job Rate], M.[Job Start Date]
> FROM Jobs Alias M
> WHERE M.[Job Rate] =
> (SELECT max([Job Rate]) as CurrentRate
> FROM Jobs Alias S
> WHERE M.[Staff ID] = S.[Staff ID])
> AND M.[Staff ID] = [S. Job ID]
>
> You can build the subquery first, test it, and then paste the SQL
> into the criteria row of the Main Query.
>
> But Is your way the right way? What if an employee gets a pay
> decrease? ( it does happen)
>
> Would it not be better to get the most recent Job date and lookup
> the salary?
>
> --
> Bob Quintal
>
> PA is y I've altered my email address.
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



Reply With Quote
  #10 (permalink)  
Old 01-06-2008, 06:11 PM
John
 
Posts: n/a
Re: Finding the date of last pay rise

Hi Ken

I have done below using the exact table/field names.

SELECT [Staff ID], MAX([Rate]) AS [Current Rate],
(SELECT MIN([Date])
FROM [Staff Bookings] AS J2
WHERE J2.[Staff ID] = J1.[Staff ID]
AND J2.[Rate] =
(SELECT MAX([Rate])
FROM [Staff Bookings] AS J3
WHERE J3.[Staff ID] = J1.[Staff ID]))
AS [Date of Last Pay Rise]
FROM [Staff Bookings] AS J1;

I am getting the error "You tried to execute a query that does not include
the specified expression 'Staff ID' as part of and aggregate function.

Thanks

Regards

"Ken Sheridan" <KenSheridan@discussions.microsoft.com> wrote in message
news:0434533D-335B-471B-85A6-BD1E91EB3F51@microsoft.com...
> Use subqueries to return the MIN Job Date for the MAX Job Rate for the
> current Staff ID, e.g.
>
> SELECT [Staff ID], MAX([Job Rate]) AS [Current Rate],
> (SELECT MIN([Job Date])
> FROM Jobs AS J2
> WHERE J2.[Staff ID] = J1.[Staff ID]
> AND J2.[Job Rate] =
> (SELECT MAX([Job Rate])
> FROM Jobs AS J3
> WHERE J3.[Staff ID] = J1.[Staff ID]))
> AS [Date of Last Pay Rise]
> FROM Jobs AS J1;
>
> Ken Sheridan
> Stafford, England
>
> "John" wrote:
>
>> Hi
>>
>> I have a Jobs table with Staff ID, Job Rate and Job Date. Staff start at
>> a
>> rate and their jobs from that day onwards have that rate. Then they get a
>> raise and this is reflected in their subsequent jobs and so on.
>>
>> I need to extract from the above table a result set which has Staff ID,
>> Max
>> of the their Rates (i.e. current salary of the staff), First Job's date
>> on
>> that Max Rate (i.e. date of last pay rise). How can I achieve this using
>> queries?
>>
>> Thanks
>>
>> Regards
>>
>>
>>

>



Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access


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

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



All times are GMT. The time now is 04:56 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Mortgage Calculator | Charity | Credit Card | Credit Cards | Debt Help



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114