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

How to list records in correspondence table Where [OutDate] Is Null AND [OutType]='06' ?

MLH
But now here's the catch - I want to see information from an
earlier record in the table.

Suppose the correspondence table had these five records

ID VehicleJobID OutDate OutType
1 150 11/24/06 14
2 151 10/12/06 14
3 152 11/24/06 11
4 150 06
5 151 06
6 152 12/20/06 06

I would like a query to extract & list records 4 and 5 this way:
ID VehicleJobID OutDate OutType Out14Date
4 150 06 11/24/06
5 151 06 10/12/06

where Out14Date is the [OutDate] field of an earlier OutType-14
record in correspondence table for the same vehicles. It's difficult
because the dynaset lists 2 rows containing information from 4
of the table's records. Extracting records 4 & 5 is a cake walk.
I mean you're only looking for OutType-06 records with Null OutDates.
But, as the query is finding these records, having it make note of
the VehicleJobID's that turn up, then rush backwards through the
same table to find an earlier OutType-14 record for the same vehicle
and including that data in the dynaset ==now that's a chore.
Applys to: PArray, Button3, frmMainMenu, Do-Item 1195
Dec 20 '06 #1
7 1886
On Wed, 20 Dec 2006 09:09:17 -0500, MLH <CR**@NorthState.netwrote:

If you want to find the record with the most recent OutDate, you'll
need a Totals query like this:
select VehicleJobID, Max(OutDate)
from Correspondence
group by VehicleJobID
Save this query. Then create a second query with the table and the
first query, joining on VehicleJobID.

-Tom.

>But now here's the catch - I want to see information from an
earlier record in the table.

Suppose the correspondence table had these five records

ID VehicleJobID OutDate OutType
1 150 11/24/06 14
2 151 10/12/06 14
3 152 11/24/06 11
4 150 06
5 151 06
6 152 12/20/06 06

I would like a query to extract & list records 4 and 5 this way:
ID VehicleJobID OutDate OutType Out14Date
4 150 06 11/24/06
5 151 06 10/12/06

where Out14Date is the [OutDate] field of an earlier OutType-14
record in correspondence table for the same vehicles. It's difficult
because the dynaset lists 2 rows containing information from 4
of the table's records. Extracting records 4 & 5 is a cake walk.
I mean you're only looking for OutType-06 records with Null OutDates.
But, as the query is finding these records, having it make note of
the VehicleJobID's that turn up, then rush backwards through the
same table to find an earlier OutType-14 record for the same vehicle
and including that data in the dynaset ==now that's a chore.
Applys to: PArray, Button3, frmMainMenu, Do-Item 1195
Dec 20 '06 #2
MLH
Kind-a-sort-a but not quite. Thx, Tom.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Wed, 20 Dec 2006 07:32:42 -0700, Tom van Stiphout
<no*************@cox.netwrote:
>On Wed, 20 Dec 2006 09:09:17 -0500, MLH <CR**@NorthState.netwrote:

If you want to find the record with the most recent OutDate, you'll
need a Totals query like this:
select VehicleJobID, Max(OutDate)
from Correspondence
group by VehicleJobID
Save this query. Then create a second query with the table and the
first query, joining on VehicleJobID.

-Tom.

>>But now here's the catch - I want to see information from an
earlier record in the table.

Suppose the correspondence table had these five records

ID VehicleJobID OutDate OutType
1 150 11/24/06 14
2 151 10/12/06 14
3 152 11/24/06 11
4 150 06
5 151 06
6 152 12/20/06 06

I would like a query to extract & list records 4 and 5 this way:
ID VehicleJobID OutDate OutType Out14Date
4 150 06 11/24/06
5 151 06 10/12/06

where Out14Date is the [OutDate] field of an earlier OutType-14
record in correspondence table for the same vehicles. It's difficult
because the dynaset lists 2 rows containing information from 4
of the table's records. Extracting records 4 & 5 is a cake walk.
I mean you're only looking for OutType-06 records with Null OutDates.
But, as the query is finding these records, having it make note of
the VehicleJobID's that turn up, then rush backwards through the
same table to find an earlier OutType-14 record for the same vehicle
and including that data in the dynaset ==now that's a chore.
Applys to: PArray, Button3, frmMainMenu, Do-Item 1195
Dec 20 '06 #3
What I'm guessing you want to do is list all correspondence records
with a Null OutDate and the OutDate of a previous correspondence record
with the same vehiclejobID and latest OutDate. If so, perhaps this
will work:

SELECT Correspondence.ID, Correspondence.VehicleJobID,
Correspondence.OutDate, Correspondence.OutType,
PreviousCorrespondence.OutDate14
FROM Correspondence INNER JOIN [SELECT Correspondence.VehicleJobID,
Max(Correspondence.OutDate) AS OutDate14
FROM Correspondence
WHERE Correspondence.OutType=14
GROUP BY Correspondence.VehicleJobID]. AS PreviousCorrespondence ON
Correspondence.VehicleJobID = PreviousCorrespondence.VehicleJobID
WHERE Correspondence.OutDate Is Null;

Bruce

Dec 20 '06 #4
MLH
Bruce, I think you may be on to something here. But I don't have two
different tables. I have tblCorrespondence only. You have named two:
Correspondence and PreviousCorrespondence. Perhaps there is a meaning
to your example that I can interpret and use, but I am having some
trouble doing so. I appreciate you taking a stab at it.

Simply stated, what is expected out of the final query is this: It is
to list certain records from tblCorrespondence meeting specified
criteria in the [OutDate] and [OutType] fields ==but only those
records for which earlier records of the same [VehicleJobID] field
value with [OutDate] and [OutType] fields of specified criteria exist
in the SAME table. Well, maybe not simply stated, but accurately
stated.

Forgive me if I have completely misinterpreted the meaning you were
trying to convey with the example.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxx

On 20 Dec 2006 11:50:47 -0800, de***************@gmail.com wrote:
>What I'm guessing you want to do is list all correspondence records
with a Null OutDate and the OutDate of a previous correspondence record
with the same vehiclejobID and latest OutDate. If so, perhaps this
will work:

SELECT Correspondence.ID, Correspondence.VehicleJobID,
Correspondence.OutDate, Correspondence.OutType,
PreviousCorrespondence.OutDate14
FROM Correspondence INNER JOIN [SELECT Correspondence.VehicleJobID,
Max(Correspondence.OutDate) AS OutDate14
FROM Correspondence
WHERE Correspondence.OutType=14
GROUP BY Correspondence.VehicleJobID]. AS PreviousCorrespondence ON
Correspondence.VehicleJobID = PreviousCorrespondence.VehicleJobID
WHERE Correspondence.OutDate Is Null;

Bruce
Dec 22 '06 #5
MLH
A working solution is to have 2 querys do the job. Below, Query6 grabs
all correspondence records of specified OutDate and OutType. Query7
grabs all correspondence records of specified (but different) OutDate
and OutType #AND# Query7 includes Query6 in the QBE grid to further
limit Query7's output. Now I know a single saved query can be
constructed to achieve achieve the same results I'm now using these
2 queries for. But I don't know how to build it. I recall seeing such
examples in this NG over the years.

This is saved as Query6:
SELECT tblCorrespondence.CorrespID, tblCorrespondence.VehicleJobID,
tblCorrespondence.OutDate, tblCorrespondence.OutType
FROM tblCorrespondence
WHERE (((tblCorrespondence.OutDate) Is Not Null) AND
((tblCorrespondence.OutType)="14"));

This is saved as Query7
SELECT tblCorrespondence.CorrespID, tblCorrespondence.VehicleJobID,
tblCorrespondence.OutDate, tblCorrespondence.OutType, Query6.OutDate
AS Type14OutDate
FROM tblCorrespondenceINNER JOIN Query6 ON
tblCorrespondence.VehicleJobID = Query6.VehicleJobID
WHERE (((tblCorrespondence.OutDate) Is Null) AND
((tblCorrespondence.OutType)="06"));

Dec 22 '06 #6
MLH
Wait! Wait! Wait! Here it is! I got it!

SELECT VehicleJobID, OutType, EXISTS (SELECT VehicleJobID FROM
tblCorrespondence AS tblC
WHERE tblC.VehicleJobID = tblCorrespondence.VehicleJobID AND
tblC.OutType = "14" AND tblC.OutDate Is Not Null) AS
YepNope FROM tblCorrespondence WHERE tblCorrespondence.OutType = "06"
AND tblCorrespondence.OutDate Is Null

I'm not much of an SQL person. If the query wizard builders cannot
build it, most of the time I just have to do without. As cool as the
wizards are, they can't do stuff like the above little EXISTS
thing-a-ma-bobber.

This little tidbit was contrbuted 99.99% by Leigh Purvis, a genius by
from the UK. Thanks again Leigh.
Dec 22 '06 #7

MLH wrote:
Bruce, I think you may be on to something here. But I don't have two
different tables. I have tblCorrespondence only. You have named two:
Correspondence and PreviousCorrespondence. Perhaps there is a meaning
to your example that I can interpret and use, but I am having some
trouble doing so. I appreciate you taking a stab at it.

Simply stated, what is expected out of the final query is this: It is
to list certain records from tblCorrespondence meeting specified
criteria in the [OutDate] and [OutType] fields ==but only those
records for which earlier records of the same [VehicleJobID] field
value with [OutDate] and [OutType] fields of specified criteria exist
in the SAME table. Well, maybe not simply stated, but accurately
stated.

Forgive me if I have completely misinterpreted the meaning you were
trying to convey with the example.
No apologies necessary. What you are seeing as a second table
(PreviousCorrespondence) is simply an alias for the first table
(Correspondence). Take the SQL I've given you and drop it into the
query designer in SQL view, then switch to design view, and you'll get
a better idea of what it does. As you've stated in later posts, you
can easily do this with two queries. This is simply a method of doing
it with a single query.

Bruce

Jan 3 '07 #8

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

Similar topics

2
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. ...
12
by: Jeff North | last post by:
I'm stumped and my brains are fried!!!! I have the following data +-------+------------------------------+------------+ | resID | FLEName | VersionNbr |...
2
by: MLH | last post by:
I feel pretty lucky on my last SQL question. I think I'll try one more... If there is a table (tblCorrespondence) with a field in it named and I am extracting a dynaset of records having an ...
2
by: karmaverma | last post by:
I need help with this apparently simple problem. I have a table with the following records: Effective_Date Commodity Price 10/1/2005 0 5/1/2006 2750 10/1/2006 ...
4
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that...
11
by: kaisersose1995 | last post by:
Hi, I've got an import procedure working, using a standard import specification to import a .csv file into a temporary table. The problem i'm having is that i have 4 different sets of borrower...
1
by: sparks | last post by:
I have a main table with teacher names and students I can put this in a subform and filter by teacher name so I have a list of her students in a sub form. the problem I have is this is created in...
7
by: ebindia0041 | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, Asp.net 1.1 with c# I'm inserting simple records into a table. But one...
3
by: Cindy | last post by:
I'm trying to use the NEWID function in dynamic SQL and get an error message Incorrect syntax near the keyword 'ORDER'. Looks like I can't do an insert with an Order by clause. Here's the code:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.