Slow query

P

PayeDoc

Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There are
~4000 records on table [staffs] and ~100,000 records in table [x conformed]:
surely these aren't large tables? To be honest I don't really understand why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax code ltr] &
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] & S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR (((X.practice)=[Forms]![frm x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1 basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));
 
J

Jeff Boyce

Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
P

PayeDoc

Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Jeff Boyce said:
Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

PayeDoc said:
Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax code ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR (((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));

 
J

Jeff Boyce

One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


PayeDoc said:
Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Jeff Boyce said:
Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

PayeDoc said:
Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax code ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR (((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));


 
J

John Spencer

PARAMETERS Forms![frm x main]![prac name] Text ( 255 )
, Forms![frm x main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName
, X.[Tax code no] & X.[Tax code ltr] & X.[mth 1 basis] AS PrevTaxCode
, S.[Tax code no] & S.[Tax code ltr] & S.[mth 1 basis] AS NewTaxCode
, X.[hourly rate] AS PrevHourlyRate
, S.[Hourly rate] AS NewHourlyRate, X.[ni code] AS PrevNIcode
, S.[NI code] AS NewNIcode
, S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X
ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name])
AND ((X.[ni code])<>.[ni code])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month]))
OR (((X.practice)=[Forms]![frm x main]![prac name])
AND ((X.[hourly rate])<>.[hourly rate])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month]))
OR (((X.practice)=[Forms]![frm x main]![prac name])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month])

AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1 basis])
<> .[Tax code no] & .[Tax code ltr] & .[mth 1 basis]));

That last AND is the culprit. Indexes are cannot be used there.

PERHAPS you can use
NOT ([X].[Tax code no] = S.[Tax Code No]
AND [X].[Tax code ltr] = .[Tax code ltr]
AND [X].[mth 1 basis] = .[mth 1 basis])

Or the equivalent
([X].[Tax code no] <> S.[Tax Code No]
OR [X].[Tax code ltr] <> .[Tax code ltr]
OR [X].[mth 1 basis] <> .[mth 1 basis])

Of course, if you have nulls in any of those fields then the expression would
be more complex. Since concatenating the three fields together will eliminate
null values as long as at least one of the fields has a value.


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Jeff said:
One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


PayeDoc said:
Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Jeff Boyce said:
Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax code ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR (((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));


 
P

PayeDoc

Hello John

Many thanks for your reply.

I have substituted both of your suggested final AND expressions, but
unfortunately the resulting queries took pretty much the same time to run as
the original!

I should add that the [mth 1 basis] field has two valid values - "M", or
null. Might it be better to alter this to "M" or "X"? Other than that, can
you think of anything else that would speed up this query?

Thanks again for your help.
Les


John Spencer said:
PARAMETERS Forms![frm x main]![prac name] Text ( 255 )
, Forms![frm x main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName
, X.[Tax code no] & X.[Tax code ltr] & X.[mth 1 basis] AS PrevTaxCode
, S.[Tax code no] & S.[Tax code ltr] & S.[mth 1 basis] AS NewTaxCode
, X.[hourly rate] AS PrevHourlyRate
, S.[Hourly rate] AS NewHourlyRate, X.[ni code] AS PrevNIcode
, S.[NI code] AS NewNIcode
, S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X
ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name])
AND ((X.[ni code])<>.[ni code])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month]))
OR (((X.practice)=[Forms]![frm x main]![prac name])
AND ((X.[hourly rate])<>.[hourly rate])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month]))
OR (((X.practice)=[Forms]![frm x main]![prac name])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month])

AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1 basis])
<> .[Tax code no] & .[Tax code ltr] & .[mth 1 basis]));

That last AND is the culprit. Indexes are cannot be used there.

PERHAPS you can use
NOT ([X].[Tax code no] = S.[Tax Code No]
AND [X].[Tax code ltr] = .[Tax code ltr]
AND [X].[mth 1 basis] = .[mth 1 basis])

Or the equivalent
([X].[Tax code no] <> S.[Tax Code No]
OR [X].[Tax code ltr] <> .[Tax code ltr]
OR [X].[mth 1 basis] <> .[mth 1 basis])

Of course, if you have nulls in any of those fields then the expression would
be more complex. Since concatenating the three fields together will eliminate
null values as long as at least one of the fields has a value.


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Jeff said:
One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


PayeDoc said:
Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and
sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax code
ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly
rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR
(((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));

 
P

PayeDoc

Hello Jeff

Thanks for your further reply.

Not sure what you mean though: I don't really understand the line
PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
at the start of the query (and I can't remember where I got it from!!), but
in any case the query does not prompt for any parameters at runtime. What
does the Text ( 255 ) mean?

Thanks again
Les



Jeff Boyce said:
One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


PayeDoc said:
Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Jeff Boyce said:
Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax code ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR (((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));


 
J

John Spencer

It might help the process to have a value other than Null in the field. And
if you only have two values for mth 1 Basis, the presence or absence of the
index is probably not going to make a lot of difference in the speed of the
query. If all the fields in the WHERE clause and the JOIN clause have
indexes, there is not a lot more you can do to speed up the query.

AND in answer to your other questions. The use of aliases for the table
should make no real difference in the performance of the query. In this
instance, the use of aliases just makes it easier to enter and edit the SQL.
After all it is much easier to type X (one character) than it is to type
[x confirmed] (13 characters)

One thing that sometimes speeds queries is to use nested queries.

You might build a query that returns the records and fields you are interested
in the table [X Confirmed]. AND then join that query to staffs instead of the
table. I have seen dramatic improvements in performance in some cases with
this technique. I think that the first query would look something like the
following. You might build this and see how fast it runs and how many records
it returns. If it is fast then try the next step of joining it to table Staffs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 )
, Forms![frm x main]![prev month] Text ( 255 );
SELECT X.practice
, X.[Tax code no]
, X.[Tax code ltr]
, X.[mth 1 basis]
, X.[hourly rate]
, X.[ni code] AS PrevNIcode
FROM staffs AS S INNER JOIN [x confirmed] AS X
ON S.name = X.name
WHERE (X.practice=[Forms]![frm x main]![prac name]
AND X.[month name]=[Forms]![frm x main]![prev month])



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Hello John

Many thanks for your reply.

I have substituted both of your suggested final AND expressions, but
unfortunately the resulting queries took pretty much the same time to run as
the original!

I should add that the [mth 1 basis] field has two valid values - "M", or
null. Might it be better to alter this to "M" or "X"? Other than that, can
you think of anything else that would speed up this query?

Thanks again for your help.
Les


John Spencer said:
PARAMETERS Forms![frm x main]![prac name] Text ( 255 )
, Forms![frm x main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName
, X.[Tax code no] & X.[Tax code ltr] & X.[mth 1 basis] AS PrevTaxCode
, S.[Tax code no] & S.[Tax code ltr] & S.[mth 1 basis] AS NewTaxCode
, X.[hourly rate] AS PrevHourlyRate
, S.[Hourly rate] AS NewHourlyRate, X.[ni code] AS PrevNIcode
, S.[NI code] AS NewNIcode
, S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X
ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name])
AND ((X.[ni code])<>.[ni code])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month]))
OR (((X.practice)=[Forms]![frm x main]![prac name])
AND ((X.[hourly rate])<>.[hourly rate])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month]))
OR (((X.practice)=[Forms]![frm x main]![prac name])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month])

AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1 basis])
<> .[Tax code no] & .[Tax code ltr] & .[mth 1 basis]));

That last AND is the culprit. Indexes are cannot be used there.

PERHAPS you can use
NOT ([X].[Tax code no] = S.[Tax Code No]
AND [X].[Tax code ltr] = .[Tax code ltr]
AND [X].[mth 1 basis] = .[mth 1 basis])

Or the equivalent
([X].[Tax code no] <> S.[Tax Code No]
OR [X].[Tax code ltr] <> .[Tax code ltr]
OR [X].[mth 1 basis] <> .[mth 1 basis])

Of course, if you have nulls in any of those fields then the expression would
be more complex. Since concatenating the three fields together will eliminate
null values as long as at least one of the fields has a value.


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Jeff said:
One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and
sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax code
ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly
rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR
(((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));

 
P

PayeDoc

John

Many thanks for this. I can see some more 'playing' will be necessary, but
at least I now have a bit more to try!!
It's Friday pm here now, and my 13 year-old's birthday paty starts soon, so
it's an early dart for me - the real playing will have to wait 'til Monday!

I'll post back then.
Have a good weekend
Les




John Spencer said:
It might help the process to have a value other than Null in the field. And
if you only have two values for mth 1 Basis, the presence or absence of the
index is probably not going to make a lot of difference in the speed of the
query. If all the fields in the WHERE clause and the JOIN clause have
indexes, there is not a lot more you can do to speed up the query.

AND in answer to your other questions. The use of aliases for the table
should make no real difference in the performance of the query. In this
instance, the use of aliases just makes it easier to enter and edit the SQL.
After all it is much easier to type X (one character) than it is to type
[x confirmed] (13 characters)

One thing that sometimes speeds queries is to use nested queries.

You might build a query that returns the records and fields you are interested
in the table [X Confirmed]. AND then join that query to staffs instead of the
table. I have seen dramatic improvements in performance in some cases with
this technique. I think that the first query would look something like the
following. You might build this and see how fast it runs and how many records
it returns. If it is fast then try the next step of joining it to table Staffs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 )
, Forms![frm x main]![prev month] Text ( 255 );
SELECT X.practice
, X.[Tax code no]
, X.[Tax code ltr]
, X.[mth 1 basis]
, X.[hourly rate]
, X.[ni code] AS PrevNIcode
FROM staffs AS S INNER JOIN [x confirmed] AS X
ON S.name = X.name
WHERE (X.practice=[Forms]![frm x main]![prac name]
AND X.[month name]=[Forms]![frm x main]![prev month])



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Hello John

Many thanks for your reply.

I have substituted both of your suggested final AND expressions, but
unfortunately the resulting queries took pretty much the same time to run as
the original!

I should add that the [mth 1 basis] field has two valid values - "M", or
null. Might it be better to alter this to "M" or "X"? Other than that, can
you think of anything else that would speed up this query?

Thanks again for your help.
Les


John Spencer said:
PARAMETERS Forms![frm x main]![prac name] Text ( 255 )
, Forms![frm x main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName
, X.[Tax code no] & X.[Tax code ltr] & X.[mth 1 basis] AS PrevTaxCode
, S.[Tax code no] & S.[Tax code ltr] & S.[mth 1 basis] AS NewTaxCode
, X.[hourly rate] AS PrevHourlyRate
, S.[Hourly rate] AS NewHourlyRate, X.[ni code] AS PrevNIcode
, S.[NI code] AS NewNIcode
, S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X
ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name])
AND ((X.[ni code])<>.[ni code])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month]))
OR (((X.practice)=[Forms]![frm x main]![prac name])
AND ((X.[hourly rate])<>.[hourly rate])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month]))
OR (((X.practice)=[Forms]![frm x main]![prac name])
AND ((S.hasLEFT)=False)
AND ((X.[month name])=[Forms]![frm x main]![prev month])

AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1 basis])
<> .[Tax code no] & .[Tax code ltr] & .[mth 1 basis]));

That last AND is the culprit. Indexes are cannot be used there.

PERHAPS you can use
NOT ([X].[Tax code no] = S.[Tax Code No]
AND [X].[Tax code ltr] = .[Tax code ltr]
AND [X].[mth 1 basis] = .[mth 1 basis])

Or the equivalent
([X].[Tax code no] <> S.[Tax Code No]
OR [X].[Tax code ltr] <> .[Tax code ltr]
OR [X].[mth 1 basis] <> .[mth 1 basis])

Of course, if you have nulls in any of those fields then the expression would
be more complex. Since concatenating the three fields together will eliminate
null values as long as at least one of the fields has a value.


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Jeff Boyce wrote:
One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and
sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax code
ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly
rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR
(((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));

 
J

Jeff Boyce

Actually, the 'prompt' is silent ... Access is checking the form named "frm
x main" for a control named "prac name" and using the value it finds there.
My suggestion would be (as a test) to make a copy of the query, eliminate
the parameter "prompt" (in design view you see this in the
Selection/Criterion row), and put an actual (hard-coded) value in that
selection criterion (actually, one in each of the two parameters).

Does the query run any faster?

Regards

Jeff Boyce
Microsoft Office/Access MVP

PayeDoc said:
Hello Jeff

Thanks for your further reply.

Not sure what you mean though: I don't really understand the line
PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
at the start of the query (and I can't remember where I got it from!!),
but
in any case the query does not prompt for any parameters at runtime. What
does the Text ( 255 ) mean?

Thanks again
Les



Jeff Boyce said:
One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


PayeDoc said:
Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and
sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax
code
ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly
rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR
(((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));


 
L

Leslie Isaacs

Jeff

OK, many thanks for that, sort of get it: I'll replace the 'prompt' with a
hard-coded value on Monday and let you know the outcome.

Thanks again
Les


Jeff Boyce said:
Actually, the 'prompt' is silent ... Access is checking the form named "frm
x main" for a control named "prac name" and using the value it finds there.
My suggestion would be (as a test) to make a copy of the query, eliminate
the parameter "prompt" (in design view you see this in the
Selection/Criterion row), and put an actual (hard-coded) value in that
selection criterion (actually, one in each of the two parameters).

Does the query run any faster?

Regards

Jeff Boyce
Microsoft Office/Access MVP

PayeDoc said:
Hello Jeff

Thanks for your further reply.

Not sure what you mean though: I don't really understand the line
PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
at the start of the query (and I can't remember where I got it from!!),
but
in any case the query does not prompt for any parameters at runtime. What
does the Text ( 255 ) mean?

Thanks again
Les



Jeff Boyce said:
One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and
sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds. There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax
code
ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly
rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR
(((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));


 
J

Jeff Boyce

Leslie

I'll also mention, in passing, that form and control names with spaces are
.... difficult. You can save yourself some potential future headaches if you
adopt a naming convention that does NOT use spaces.

Regards

Jeff Boyce
Microsoft Office/Access MVP

Leslie Isaacs said:
Jeff

OK, many thanks for that, sort of get it: I'll replace the 'prompt' with
a hard-coded value on Monday and let you know the outcome.

Thanks again
Les


Jeff Boyce said:
Actually, the 'prompt' is silent ... Access is checking the form named "frm
x main" for a control named "prac name" and using the value it finds there.
My suggestion would be (as a test) to make a copy of the query, eliminate
the parameter "prompt" (in design view you see this in the
Selection/Criterion row), and put an actual (hard-coded) value in that
selection criterion (actually, one in each of the two parameters).

Does the query run any faster?

Regards

Jeff Boyce
Microsoft Office/Access MVP

PayeDoc said:
Hello Jeff

Thanks for your further reply.

Not sure what you mean though: I don't really understand the line
PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
at the start of the query (and I can't remember where I got it from!!),
but
in any case the query does not prompt for any parameters at runtime. What
does the Text ( 255 ) mean?

Thanks again
Les



One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of
prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and
sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds.
There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax
code
ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly
rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS
NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR
(((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));


 
L

Leslie Isaacs

Thanks for the tip Jeff - I'll bear that in mind.
I knew that reserved words were a no-no (and you may recall that have have
a field name 'name' that's all over our mdb and which I haven't yet steeled
myself to eradicate!), but the only problem with spaces that I was aware of
was the need to use []s around them in expressions etc. Are there other
issues?

Thanks again
Les


Jeff Boyce said:
Leslie

I'll also mention, in passing, that form and control names with spaces are
... difficult. You can save yourself some potential future headaches if you
adopt a naming convention that does NOT use spaces.

Regards

Jeff Boyce
Microsoft Office/Access MVP

Leslie Isaacs said:
Jeff

OK, many thanks for that, sort of get it: I'll replace the 'prompt' with
a hard-coded value on Monday and let you know the outcome.

Thanks again
Les


Jeff Boyce said:
Actually, the 'prompt' is silent ... Access is checking the form
named
"frm
x main" for a control named "prac name" and using the value it finds there.
My suggestion would be (as a test) to make a copy of the query, eliminate
the parameter "prompt" (in design view you see this in the
Selection/Criterion row), and put an actual (hard-coded) value in that
selection criterion (actually, one in each of the two parameters).

Does the query run any faster?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello Jeff

Thanks for your further reply.

Not sure what you mean though: I don't really understand the line
PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
at the start of the query (and I can't remember where I got it from!!),
but
in any case the query does not prompt for any parameters at
runtime.
What
does the Text ( 255 ) mean?

Thanks again
Les



One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of
prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins and
sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45 seconds.
There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that
makes
a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax
code
ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate, S.[Hourly
rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS
NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name = X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND ((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR
(((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));


 
J

Jeff Boyce

If you're using the "[ ]" (square brackets), you'll have most situations
covered... until you upsize to SQL-Server or ?other more robust back-ends.
One option for eliminating spaces is to use "CamelCase", in which the first
letter of each word is capitalized.

Gool luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP

Leslie Isaacs said:
Thanks for the tip Jeff - I'll bear that in mind.
I knew that reserved words were a no-no (and you may recall that have
have a field name 'name' that's all over our mdb and which I haven't yet
steeled myself to eradicate!), but the only problem with spaces that I was
aware of was the need to use []s around them in expressions etc. Are there
other issues?

Thanks again
Les


Jeff Boyce said:
Leslie

I'll also mention, in passing, that form and control names with spaces are
... difficult. You can save yourself some potential future headaches if you
adopt a naming convention that does NOT use spaces.

Regards

Jeff Boyce
Microsoft Office/Access MVP

Leslie Isaacs said:
Jeff

OK, many thanks for that, sort of get it: I'll replace the 'prompt' with
a hard-coded value on Monday and let you know the outcome.

Thanks again
Les


Actually, the 'prompt' is silent ... Access is checking the form named
"frm
x main" for a control named "prac name" and using the value it finds
there.
My suggestion would be (as a test) to make a copy of the query,
eliminate
the parameter "prompt" (in design view you see this in the
Selection/Criterion row), and put an actual (hard-coded) value in that
selection criterion (actually, one in each of the two parameters).

Does the query run any faster?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello Jeff

Thanks for your further reply.

Not sure what you mean though: I don't really understand the line
PARAMETERS Forms![frm x main]![prac name] Text ( 255 ), Forms![frm x
main]![prev month] Text ( 255 );
at the start of the query (and I can't remember where I got it
from!!),
but
in any case the query does not prompt for any parameters at runtime.
What
does the Text ( 255 ) mean?

Thanks again
Les



One down, ...

Is the query as slow if you try 'hard-coded' parameters instead of
prompting
for them?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hello Jeff

Thanks for your reply.
Yep - all 'indexed - Duplicates OK'.

What next?!
Les


Leslie

You may have already addressed this ...

Are all fields used in your query for selection criteria, joins
and
sorting
indexed in their underlying tables?

Regards

Jeff Boyce
Microsoft Office/Access MVP

Hello All

Why is the query below so slow - it normally takes 30-45
seconds.
There
are
~4000 records on table [staffs] and ~100,000 records in table [x
conformed]:
surely these aren't large tables? To be honest I don't really
understand
why
the two tables are 'aliased' in the query, or whether that makes
a
difference.

Hope someone can help.
Thanks as ever
Leslie Isaacs

PARAMETERS Forms![frm x main]![prac name] Text ( 255 ),
Forms![frm x
main]![prev month] Text ( 255 );
SELECT X.practice, S.name AS StaffName, X.[Tax code no] & X.[Tax
code
ltr]
&
X.[mth 1 basis] AS PrevTaxCode, S.[Tax code no] & S.[Tax code
ltr] &
S.[mth
1 basis] AS NewTaxCode, X.[hourly rate] AS PrevHourlyRate,
S.[Hourly
rate]
AS NewHourlyRate, X.[ni code] AS PrevNIcode, S.[NI code] AS
NewNIcode,
S.hasLEFT
FROM staffs AS S INNER JOIN [x confirmed] AS X ON S.name =
X.name
WHERE (((X.practice)=[Forms]![frm x main]![prac name]) AND
((X.[ni
code])<>.[ni code]) AND ((S.hasLEFT)=False) AND ((X.[month
name])=[Forms]![frm x main]![prev month])) OR
(((X.practice)=[Forms]![frm
x
main]![prac name]) AND ((X.[hourly rate])<>.[hourly rate])
AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x
main]![prev
month])) OR (((X.practice)=[Forms]![frm x main]![prac name]) AND
((S.hasLEFT)=False) AND ((X.[month name])=[Forms]![frm x
main]![prev
month])
AND (([X].[Tax code no] & [X].[Tax code ltr] & [X].[mth 1
basis])<>.[Tax
code no] & .[Tax code ltr] & .[mth 1 basis]));


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top