473,411 Members | 2,185 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,411 software developers and data experts.

access97 / sql server, how to speed up this query

SELECT distinct b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b, tblFilterDate, tblFilterDate AS
tblFilterDate_1
WHERE (((b.t_yearMonth) Between [tblfilterdate].[fromDate] And
[tblFilterDate_1].[toDate]));

tblMonthlyBooking is a sql server table, 200K rows, yearMonth is an
indexed long integer
the primary key is t_orno, t_pono

tblFilterDate is an access table used to store reporting criteria, and
it will always only have one row, yearMonth is an indexed long integer
this query takes approx 3 minutes to run, so does this one
SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE (((b.t_yearMonth)>=(select fromYearMonth from tblFilterDate where
dateId = 1) And (b.t_yearMonth)<=(select toYearMonth from tblFilterDate
where dateId = 1)));

this one is runs in a second
SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE (((b.t_yearMonth)>=98 And (b.t_yearMonth)<=99));

if I load 'fromYearMonth' and 'toYearMonth' into a form's textboxes,
and change the query to refer to the form fields, again the query runs
in a second

showplan.out for the long running query refers to a temporary table
01) Restrict rows of table tblMonthlyBooking
by scanning
testing expression "b.t_yearMonth>= And b.t_yearMonth<="
store result in temporary table

is there another way to build this query, to make use of the two
tables, and have results in a second ?

note, the tblFilterDate table cannot be moved to sqlServer, that would
be a massive reengineering exercise

Mar 21 '06 #1
6 3258

<le*********@natpro.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
SELECT distinct b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b, tblFilterDate, tblFilterDate AS
tblFilterDate_1
WHERE (((b.t_yearMonth) Between [tblfilterdate].[fromDate] And
[tblFilterDate_1].[toDate]));

tblMonthlyBooking is a sql server table, 200K rows, yearMonth is an
indexed long integer
the primary key is t_orno, t_pono

tblFilterDate is an access table used to store reporting criteria, and
it will always only have one row, yearMonth is an indexed long integer
this query takes approx 3 minutes to run, so does this one
SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE (((b.t_yearMonth)>=(select fromYearMonth from tblFilterDate where
dateId = 1) And (b.t_yearMonth)<=(select toYearMonth from tblFilterDate
where dateId = 1)));

this one is runs in a second
SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE (((b.t_yearMonth)>=98 And (b.t_yearMonth)<=99));

if I load 'fromYearMonth' and 'toYearMonth' into a form's textboxes,
and change the query to refer to the form fields, again the query runs
in a second

showplan.out for the long running query refers to a temporary table
01) Restrict rows of table tblMonthlyBooking
by scanning
testing expression "b.t_yearMonth>= And b.t_yearMonth<="
store result in temporary table

is there another way to build this query, to make use of the two
tables, and have results in a second ?

note, the tblFilterDate table cannot be moved to sqlServer, that would
be a massive reengineering exercise

I would prefer the following which should be faster and is certainly easier
to read:

SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE b.t_yearMonth BETWEEN 98 AND 99

But what about using both tables?
Come on, you're not serious, right?
The local Jet table is restricted to one row and its purpose is store a
MinValue and a MaxValue for your reporting purposes. This is fine, and may
be useful in letting you close the database and remember these settings -
but they are only really settings and trying to join these tables for the
single purpose of passing two parameters to your SQL Server database isn't
really sensible.

The best solution will depend on a number of things:
Are you using linked tables
Are you able to create server objects such as a stored procedure, a view,
etc
Do you have a preference for DAO or ADO code
Is the recordset you return to be read-only or not.

One option would be to create a stored procedure on the server, with two
parameters for the min and max value. You could then generate a recordset
by using ADO to execute the recordset, passing in the values which it looks
up from your local table.
Another option might be to look up the values, then dynamically re-write a
pass-through query to get the records.
Mar 21 '06 #2
le*********@natpro.com wrote in
news:11**********************@u72g2000cwu.googlegr oups.com:
SELECT distinct b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b, tblFilterDate, tblFilterDate AS
tblFilterDate_1
WHERE (((b.t_yearMonth) Between [tblfilterdate].[fromDate] And
[tblFilterDate_1].[toDate]));

tblMonthlyBooking is a sql server table, 200K rows, yearMonth
is an indexed long integer
the primary key is t_orno, t_pono

tblFilterDate is an access table used to store reporting
criteria, and it will always only have one row, yearMonth is
an indexed long integer
Why are you using two instances of tblfilterdate???? Because of
the cartesian joins, this will produce double the number of
rows, which must be reduced again by the select distinct.

Reccomendation:
SELECT distinct
b.t_orno,
b.t_pono
FROM tblMonthlyBooking AS b,
tblFilterDate,
WHERE b.t_yearMonth Between [tblfilterdate].[fromDate] And
[tblFilterDate].[toDate];

you may not even need the distinct statement any more.

this query takes approx 3 minutes to run, so does this one
SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE (((b.t_yearMonth)>=(select fromYearMonth from
tblFilterDate where dateId = 1) And (b.t_yearMonth)<=(select
toYearMonth from tblFilterDate where dateId = 1)));

this one is runs in a second
SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE (((b.t_yearMonth)>=98 And (b.t_yearMonth)<=99));

if I load 'fromYearMonth' and 'toYearMonth' into a form's
textboxes, and change the query to refer to the form fields,
again the query runs in a second

showplan.out for the long running query refers to a temporary
table
01) Restrict rows of table tblMonthlyBooking
by scanning
testing expression "b.t_yearMonth>= And
b.t_yearMonth<=" store result in temporary table

is there another way to build this query, to make use of the
two tables, and have results in a second ?

note, the tblFilterDate table cannot be moved to sqlServer,
that would be a massive reengineering exercise


--
Bob Quintal

PA is y I've altered my email address.
Mar 21 '06 #3
On Tue, 21 Mar 2006 22:49:24 GMT, Bob Quintal <rq******@sympatico.ca>
wrote:

Not double, but the square.
-Tom.

<clip>
Why are you using two instances of tblfilterdate???? Because of
the cartesian joins, this will produce double the number of
rows, which must be reduced again by the select distinct.

<clip>
Mar 23 '06 #4
> Are you using linked tables
yes
Are you able to create server objects such as a stored procedure, a view, etc yes
Do you have a preference for DAO or ADO code access97, so DAO
Is the recordset you return to be read-only or not. yes

If I store the parameters as text boxes on a hidden form and refer to
the text boxes as parameters in my query, query timing is substantially
improved

I thought access would do the same optimization when using a small
table, but obvious not

I will look at using a stored procedure ... thanks

Anthony England wrote: <le*********@natpro.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
SELECT distinct b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b, tblFilterDate, tblFilterDate AS
tblFilterDate_1
WHERE (((b.t_yearMonth) Between [tblfilterdate].[fromDate] And
[tblFilterDate_1].[toDate]));

tblMonthlyBooking is a sql server table, 200K rows, yearMonth is an
indexed long integer
the primary key is t_orno, t_pono

tblFilterDate is an access table used to store reporting criteria, and
it will always only have one row, yearMonth is an indexed long integer
this query takes approx 3 minutes to run, so does this one
SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE (((b.t_yearMonth)>=(select fromYearMonth from tblFilterDate where
dateId = 1) And (b.t_yearMonth)<=(select toYearMonth from tblFilterDate
where dateId = 1)));

this one is runs in a second
SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE (((b.t_yearMonth)>=98 And (b.t_yearMonth)<=99));

if I load 'fromYearMonth' and 'toYearMonth' into a form's textboxes,
and change the query to refer to the form fields, again the query runs
in a second

showplan.out for the long running query refers to a temporary table
01) Restrict rows of table tblMonthlyBooking
by scanning
testing expression "b.t_yearMonth>= And b.t_yearMonth<="
store result in temporary table

is there another way to build this query, to make use of the two
tables, and have results in a second ?

note, the tblFilterDate table cannot be moved to sqlServer, that would
be a massive reengineering exercise

I would prefer the following which should be faster and is certainly easier
to read:

SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE b.t_yearMonth BETWEEN 98 AND 99

But what about using both tables?
Come on, you're not serious, right?
The local Jet table is restricted to one row and its purpose is store a
MinValue and a MaxValue for your reporting purposes. This is fine, and may
be useful in letting you close the database and remember these settings -
but they are only really settings and trying to join these tables for the
single purpose of passing two parameters to your SQL Server database isn't
really sensible.

The best solution will depend on a number of things:
Are you using linked tables
Are you able to create server objects such as a stored procedure, a view,
etc
Do you have a preference for DAO or ADO code
Is the recordset you return to be read-only or not.

One option would be to create a stored procedure on the server, with two
parameters for the min and max value. You could then generate a recordset
by using ADO to execute the recordset, passing in the values which it looks
up from your local table.
Another option might be to look up the values, then dynamically re-write a
pass-through query to get the records.


Mar 27 '06 #5
Thanks for the feedback.
Another alternative would be to create a SQL Server view.
You can create an Access table linked to this view as if it were a table.

<le*********@natpro.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Are you using linked tables

yes
Are you able to create server objects such as a stored procedure, a view,
etc

yes
Do you have a preference for DAO or ADO code

access97, so DAO
Is the recordset you return to be read-only or not.

yes

If I store the parameters as text boxes on a hidden form and refer to
the text boxes as parameters in my query, query timing is substantially
improved

I thought access would do the same optimization when using a small
table, but obvious not

I will look at using a stored procedure ... thanks

Anthony England wrote:
<le*********@natpro.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
> SELECT distinct b.t_orno, b.t_pono
> FROM tblMonthlyBooking AS b, tblFilterDate, tblFilterDate AS
> tblFilterDate_1
> WHERE (((b.t_yearMonth) Between [tblfilterdate].[fromDate] And
> [tblFilterDate_1].[toDate]));
>
> tblMonthlyBooking is a sql server table, 200K rows, yearMonth is an
> indexed long integer
> the primary key is t_orno, t_pono
>
> tblFilterDate is an access table used to store reporting criteria, and
> it will always only have one row, yearMonth is an indexed long integer
>
>
> this query takes approx 3 minutes to run, so does this one
> SELECT DISTINCT b.t_orno, b.t_pono
> FROM tblMonthlyBooking AS b
> WHERE (((b.t_yearMonth)>=(select fromYearMonth from tblFilterDate where
> dateId = 1) And (b.t_yearMonth)<=(select toYearMonth from tblFilterDate
> where dateId = 1)));
>
> this one is runs in a second
> SELECT DISTINCT b.t_orno, b.t_pono
> FROM tblMonthlyBooking AS b
> WHERE (((b.t_yearMonth)>=98 And (b.t_yearMonth)<=99));
>
> if I load 'fromYearMonth' and 'toYearMonth' into a form's textboxes,
> and change the query to refer to the form fields, again the query runs
> in a second
>
> showplan.out for the long running query refers to a temporary table
> 01) Restrict rows of table tblMonthlyBooking
> by scanning
> testing expression "b.t_yearMonth>= And b.t_yearMonth<="
> store result in temporary table
>
> is there another way to build this query, to make use of the two
> tables, and have results in a second ?
>
> note, the tblFilterDate table cannot be moved to sqlServer, that would
> be a massive reengineering exercise

I would prefer the following which should be faster and is certainly
easier
to read:

SELECT DISTINCT b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b
WHERE b.t_yearMonth BETWEEN 98 AND 99

But what about using both tables?
Come on, you're not serious, right?
The local Jet table is restricted to one row and its purpose is store a
MinValue and a MaxValue for your reporting purposes. This is fine, and
may
be useful in letting you close the database and remember these settings -
but they are only really settings and trying to join these tables for the
single purpose of passing two parameters to your SQL Server database
isn't
really sensible.

The best solution will depend on a number of things:
Are you using linked tables
Are you able to create server objects such as a stored procedure, a view,
etc
Do you have a preference for DAO or ADO code
Is the recordset you return to be read-only or not.

One option would be to create a stored procedure on the server, with two
parameters for the min and max value. You could then generate a
recordset
by using ADO to execute the recordset, passing in the values which it
looks
up from your local table.
Another option might be to look up the values, then dynamically re-write
a
pass-through query to get the records.

Mar 27 '06 #6
le*********@natpro.com wrote in news:1142937414.254928.223190
@u72g2000cwu.googlegroups.com:
SELECT distinct b.t_orno, b.t_pono
FROM tblMonthlyBooking AS b, tblFilterDate, tblFilterDate AS
tblFilterDate_1
WHERE (((b.t_yearMonth) Between [tblfilterdate].[fromDate] And
[tblFilterDate_1].[toDate]));


Joins are often faster and more efficient than Wheres.
Without seeing your tables I can't be completely accurate but I think
something like

SELECT tmb.*
FROM tblMonthBooking AS tmb
INNER JOIN tblFilterDate AS tfd
ON (tmb.t_YearMonth BETWEEN tfd.fromDate AND tfd.toDate)

modified for your exact requirements should be quite fast.

It's inlikley the query-grid-wizard nonsense window will be able to
represent the JOIN given so one would have to use the SQL view to create
the query or VBA to create or run it.

If yearMonth is Integer and fromDate and toDate are Dates I'm not sure how
the Between works, but that's another issue.

When one is doing Dates, Between often fails to do what one wants and more
accurate results may be achieved with something like

tmb.t_YearMonth >= tfd.fromDate (includes fromDate)
AND
tmb.t_YearMonth < tfd.fromDate (excludes toDate).

--
Lyle Fairfield
Mar 27 '06 #7

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

Similar topics

5
by: JENS CONSER | last post by:
Hello NG, We have a performance problem in using a client server solution based on MS SQL-Server 2000 through a VPN tunnel (via broadband internet connection). The SQL Server is running on a...
1
by: ChaimG | last post by:
Hi everyone, I Run DB Application using Access97 (with DAO) on XP Client and Windows2000 Server (Version5, SP4) with active directory. A Simple "Select *" Query takes no time ( less then...
5
by: Chris Dugan | last post by:
Hi, has anybody come across a solution to running an Access97 database on Windows XP. The situation I have is an Access 97 database that runs perfectly from Win95/98 clients running Access97, the...
8
by: Rebecca | last post by:
We are converting my Access97 back end to SQL Server and almost have it all working. The current problem has to do with one situation in which I have to programmatically (still in the Access97...
0
by: lesperancer | last post by:
I've got a sql server view that returns data, as a linked table to access97 (qryPlannedPurPT) this link table is used in an access query (qryPlannedPUR) that uses all of the linked table fields...
1
by: lesperancer | last post by:
currently using access97 to link to sql7 tables sql7 is running on NT4 and terminal server 2000 in the process of upgrading hardware and software to latest stable versions citrix - windows 2003...
0
by: Roger | last post by:
can anyone explain this ? originally using access97 with a linked table to an mdb backend, to create a worksheet using SELECT * FROM qryIPS WHERE location = 999 and it works fine with either...
3
by: Ramchandar | last post by:
Hi, I am creating reports using VBA code. I have the same query in a querydef residing both in Access97 and Access2003. The result of this querydef is then moved to a table in Access97 and...
4
by: Roger | last post by:
on sql 2005, I've got a view with select permission granted, the view just "select * from table" using odbc in access97, I linked this view and I create a query to retrieve certain fields the...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.