473,396 Members | 1,929 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.

Slightly more complex SELECT query syntax in A97

MLH
I have a table (tblCorrespondence) holding records with fields like
[CorrespID], [VehicleJobID], [UserID], [OutType], [OutDate], [InType],
[InDate], etc...

About a dozen [OutType]'s are defined and I often use queries to
extract records of a given [OutType]. That's pretty easy.

But, recently, I wanted to list all [OutType] "15" letters, a few of
the above mentioned fields and one additional field: [OutDate] of
nother letter [OutType] "00" in the same row. That's the tough part.
It can't be simply built in the QBE grid - that much is for sure. The
[OutType] "00" correspondence record would have been created about 15
weeks earlier than the [OutType] "15" record. Listing it in the same
row is essential to my objective.

So, I'm hoping to extract a dynaset that looks something like this...
Select records where [OutType] = "15"
[CorrespID] [VehicleJobID] [UserID] [OutDate] [Type00OutDate]
159 195 17 10/15/05 7/1/05
164 200 17 10/17/05 7/3/05
168 210 17 10/22/05 7/6/05
and so on...

For each vehicle in vehicles table, there is only one correspondence
record for any given outbound letter type. This is quite difficult. I
would like to learn how this type of SQL is built. Am hoping that
someone in the NG is an SQL master and could point out some good
on-line reference material for building this kind of query. I don't
know what you call it other than a SELECT query. But it is definitely
in a different category that a simple

SELECT [CorrespID], [VehicleJobID], [OutDate], [OutType] FROM
tblCorrespondence WHERE [OutType]="00";
Nov 13 '05 #1
9 2829
MLH
BTW, my first stab at it...

SELECT CorrespID, VehicleJobID, tblOutboundTypes.Title, OutType,
OutDate, DLookUp("[OutDate]","tblCorrespondence","[OutType]='00'") AS
260OutDate
FROM tblOutboundTypes INNER JOIN tblCorrespondence ON
tblOutboundTypes.OutType = OutType
WHERE OutType="01";

fell miserably short of being anywhere near right!
Nov 13 '05 #2
MLH wrote:
I have a table (tblCorrespondence) holding records with fields like
[CorrespID], [VehicleJobID], [UserID], [OutType], [OutDate], [InType],
[InDate], etc...

About a dozen [OutType]'s are defined and I often use queries to
extract records of a given [OutType]. That's pretty easy.

But, recently, I wanted to list all [OutType] "15" letters, a few of
the above mentioned fields and one additional field: [OutDate] of
nother letter [OutType] "00" in the same row. That's the tough part.
It can't be simply built in the QBE grid - that much is for sure. The
[OutType] "00" correspondence record would have been created about 15
weeks earlier than the [OutType] "15" record. Listing it in the same
row is essential to my objective.

So, I'm hoping to extract a dynaset that looks something like this...
Select records where [OutType] = "15"
[CorrespID] [VehicleJobID] [UserID] [OutDate] [Type00OutDate]
159 195 17 10/15/05 7/1/05
164 200 17 10/17/05 7/3/05
168 210 17 10/22/05 7/6/05
and so on...

For each vehicle in vehicles table, there is only one correspondence
record for any given outbound letter type. This is quite difficult. I
would like to learn how this type of SQL is built. Am hoping that
someone in the NG is an SQL master and could point out some good
on-line reference material for building this kind of query. I don't
know what you call it other than a SELECT query. But it is definitely
in a different category that a simple

SELECT [CorrespID], [VehicleJobID], [OutDate], [OutType] FROM
tblCorrespondence WHERE [OutType]="00";


If I wanted it to be fast, I would create two queries. The first query
would be Query00. It would select the CorrespID and whatever additional
fields required for "00" records and filter for type "00".

I would then create a new query and add tblCorrespondence and Query00.
Set a relationship between the two...perhaps make it a left join if some
records may not have a "00" record.

Although you are using 2 queries it will be much faster that using
Dlookup or subquery.

You can even make the type a parameter for added flexibility.

In your other post, you said Dlookup wasn't working right. You probably
needed to select the record where the type was "00" and the ID equal to
the current records ID. I think you left that out.
Nov 13 '05 #3
MLH
Thx, Salad. That was perfect. Here's the resultant SQL...

SELECT tblCorrespondence.CorrespID, tblCorrespondence.OutType,
tblCorrespondence.OutDate, Query00.CorrespID, Query00.OutDate
FROM tblCorrespondence INNER JOIN Query00 ON
tblCorrespondence.VehicleJobID = Query00.VehicleJobID
WHERE (((tblCorrespondence.OutType)="01"));

If I wanted it to be fast, I would create two queries. The first query
would be Query00. It would select the CorrespID and whatever additional
fields required for "00" records and filter for type "00".

I would then create a new query and add tblCorrespondence and Query00.
Set a relationship between the two...perhaps make it a left join if some
records may not have a "00" record.

Although you are using 2 queries it will be much faster that using
Dlookup or subquery.

You can even make the type a parameter for added flexibility.

Now that sounds interesting. I could list the outdate of the type "00"
letters in a dynaset of records of any other outype I wanted. Haven't
fooled with parameter queries, but this is a good case to try it on.
I'll have a go at it.
Nov 13 '05 #4
MLH
Well, the parameter query was a cinch...
SELECT tblCorrespondence.CorrespID, tblCorrespondence.OutType,
tblCorrespondence.OutDate, Query00.CorrespID, Query00.OutDate
FROM tblCorrespondence INNER JOIN Query00 ON
tblCorrespondence.VehicleJobID = Query00.VehicleJobID
WHERE (((tblCorrespondence.OutType)=[Which OutType?]) AND
((tblCorrespondence.OutDate) Is Not Null));

Thx for the suggestion. A question comes to mind, though. If I have
a form or report feeding off the parameter query, can I slip the query
its parameter somehow, eliminating the need for user input at the
keyboard? If I can, then I can use this query with a number of forms
and reports.

You can even make the type a parameter for added flexibility.

Nov 13 '05 #5
MLH
I found a 4-yr old post where Larry Linson discussed a work-around.
I can barely recall having toyed with this. Anyway, I don't think its
an easy thing to do. Larry would undoubtedly have mentioned any
simple solution.
Nov 13 '05 #6
MLH wrote:
Well, the parameter query was a cinch...
SELECT tblCorrespondence.CorrespID, tblCorrespondence.OutType,
tblCorrespondence.OutDate, Query00.CorrespID, Query00.OutDate
FROM tblCorrespondence INNER JOIN Query00 ON
tblCorrespondence.VehicleJobID = Query00.VehicleJobID
WHERE (((tblCorrespondence.OutType)=[Which OutType?]) AND
((tblCorrespondence.OutDate) Is Not Null));

Thx for the suggestion. A question comes to mind, though. If I have
a form or report feeding off the parameter query, can I slip the query
its parameter somehow, eliminating the need for user input at the
keyboard? If I can, then I can use this query with a number of forms
and reports.
You can even make the type a parameter for added flexibility.


You could try to store the types in a Vistible=False control. Then in
Query00 and the other query remove the [Enter Type] and do something like
Forms!MainForm!HiddenType
Doing it like that is explicitly defining the form tho. You can set the
parameter values prior to opening the query. Lyle provided a good example.

You could even create a function. But this would slow things down. If
you can handle the explicit, that would be best...drag the field to a
column and enter in the criteria
Forms!MainForm!HiddenType

Nov 13 '05 #8
Salad <oi*@vinegar.com> wrote in
news:SV***************@newsread2.news.pas.earthlin k.net:
Although you are using 2 queries it will be much faster that using
Dlookup or subquery.


Er, what subqueries will it be slower than?

If you use:

SELECT ...
FROM table JOIN [other SQL]. As othertable ON table.field =
othertable.field;

then it should be just as fast as two saved queries joined together.

"Virtual tables" (the ones where you take the SQL for a SELECT query
and put it between []. As alias), is optimized and very fast.

Indeed, most subqueries are very fast (except for correlated
subqueries, which *can't* be fast, since the subquery has to be
executed individually for each row).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9
MLH <CR**@NorthState.net> wrote in
news:uv********************************@4ax.com:
Well, the parameter query was a cinch...
SELECT tblCorrespondence.CorrespID, tblCorrespondence.OutType,
tblCorrespondence.OutDate, Query00.CorrespID, Query00.OutDate
FROM tblCorrespondence INNER JOIN Query00 ON
tblCorrespondence.VehicleJobID = Query00.VehicleJobID
WHERE (((tblCorrespondence.OutType)=[Which OutType?]) AND
((tblCorrespondence.OutDate) Is Not Null));

Thx for the suggestion. A question comes to mind, though. If I
have a form or report feeding off the parameter query, can I slip
the query its parameter somehow, eliminating the need for user
input at the keyboard? If I can, then I can use this query with a
number of forms and reports.


To me, parameters make saved queries *LESS FLEXIBLE*, since they
can
only be used in contexts where you can set the parameters in code,
or the user has to fill them out.

It's just much easier to write the SQL on the fly with a virtual
table. Taking your SQL as starting point:

SELECT tblCorrespondence.CorrespID, tblCorrespondence.OutType,
tblCorrespondence.OutDate, Query00.CorrespID, Query00.OutDate
FROM tblCorrespondence INNER JOIN [SQL from QueryOO]. As Query00 ON
tblCorrespondence.VehicleJobID = Query00.VehicleJobID
WHERE (((tblCorrespondence.OutType)="00") AND
((tblCorrespondence.OutDate) Is Not Null));

will allow you to write the WHERE clause on the spot, it one single
SQL statement.

Of course, I don't quite understand what the hell you're doing
here,
as I don't see any reason why you'd couldn't just join the two base
tables and put criteria on the two tables. I think this is because
your explanation of the table structure involved was too hazy so I
never quite understood what you were going for.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #10

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

Similar topics

39
by: | last post by:
I am trying to run the following agregate function in a parameterized query on Access2000: Min(.*sqr(./.)/) The query saved OK, but an attempt to run it results in the message: The expression...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
5
by: Bob Stearns | last post by:
Is there an easy way (without duplication of the complex expression) to use the same complex expression in all three places? Will something like this work? WITH (SELECT t.*, <complex expr> AS...
11
by: ynott | last post by:
Novice here obviously. Anyway, I'm a bit confused about how to approach this. I have a query against a table that I'm trying to create. I'm trying to view all streets.type values that are null,...
0
by: schan | last post by:
Hi there, I was wondering if someone could shed some light on a problem I have no idea on how to fix. I created an Excel Add-In that uses an ADO connection to an Access database on a file...
10
by: jerry.ranch | last post by:
I get extracts/reports from a corporate Sybase database. This is a very very large transactional database, very little (or slow and complex) reports/queries, so instead I have an all-inclusive...
6
by: alex | last post by:
Hello experts. I'm a novice sql writer and need some help in writing a query to extract applicable data from the following table (titled EMPLOYEE): -- ID_NUMBER CODE DATE ------------------ ...
1
dlite922
by: dlite922 | last post by:
hey fellas (and ladies) I need help with making a query. My tables are: (Simplified) case: id violatorID number
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
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?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.