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 7 1901
On Wed, 20 Dec 2006 09:09:17 -0500, MLH <CR**@NorthStat e.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
Kind-a-sort-a but not quite. Thx, Tom.
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxx
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**@NorthStat e.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
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,
PreviousCorresp ondence.OutDate 14
FROM Correspondence INNER JOIN [SELECT Correspondence. VehicleJobID,
Max(Corresponde nce.OutDate) AS OutDate14
FROM Correspondence
WHERE Correspondence. OutType=14
GROUP BY Correspondence. VehicleJobID]. AS PreviousCorresp ondence ON
Correspondence. VehicleJobID = PreviousCorresp ondence.Vehicle JobID
WHERE Correspondence. OutDate Is Null;
Bruce
Bruce, I think you may be on to something here. But I don't have two
different tables. I have tblCorresponden ce only. You have named two:
Correspondence and PreviousCorresp ondence. 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 tblCorresponden ce 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.
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxx
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, PreviousCorres pondence.OutDat e14 FROM Correspondence INNER JOIN [SELECT Correspondence. VehicleJobID, Max(Correspond ence.OutDate) AS OutDate14 FROM Correspondence WHERE Correspondence. OutType=14 GROUP BY Correspondence. VehicleJobID]. AS PreviousCorresp ondence ON Correspondence .VehicleJobID = PreviousCorresp ondence.Vehicle JobID WHERE Correspondence. OutDate Is Null;
Bruce
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 tblCorresponden ce.CorrespID, tblCorresponden ce.VehicleJobID ,
tblCorresponden ce.OutDate, tblCorresponden ce.OutType
FROM tblCorresponden ce
WHERE (((tblCorrespon dence.OutDate) Is Not Null) AND
((tblCorrespond ence.OutType)=" 14"));
This is saved as Query7
SELECT tblCorresponden ce.CorrespID, tblCorresponden ce.VehicleJobID ,
tblCorresponden ce.OutDate, tblCorresponden ce.OutType, Query6.OutDate
AS Type14OutDate
FROM tblCorresponden ceINNER JOIN Query6 ON
tblCorresponden ce.VehicleJobID = Query6.VehicleJ obID
WHERE (((tblCorrespon dence.OutDate) Is Null) AND
((tblCorrespond ence.OutType)=" 06"));
Wait! Wait! Wait! Here it is! I got it!
SELECT VehicleJobID, OutType, EXISTS (SELECT VehicleJobID FROM
tblCorresponden ce AS tblC
WHERE tblC.VehicleJob ID = tblCorresponden ce.VehicleJobID AND
tblC.OutType = "14" AND tblC.OutDate Is Not Null) AS
YepNope FROM tblCorresponden ce WHERE tblCorresponden ce.OutType = "06"
AND tblCorresponden ce.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.
MLH wrote:
Bruce, I think you may be on to something here. But I don't have two
different tables. I have tblCorresponden ce only. You have named two:
Correspondence and PreviousCorresp ondence. 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 tblCorresponden ce 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
(PreviousCorres pondence) 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
I'm inserting simple records into a table. But one insert command is
placing 2 or 3 records into the table. The 'extra' records, have the
same data as the previous insert incident, (except for the timestamp).
|
by: Jeff North |
last post by:
I'm stumped and my brains are fried!!!!
I have the following data
+-------+------------------------------+------------+
| resID | FLEName | VersionNbr |
+-------+------------------------------+------------+
| 1 | 35_laserdatandria2104.zip | 1.0 |
| 2 | 35_laserdatandria2104.zip | 1.23 |
| 3 | 35_microweb1.31.zip | 1.0 |
| 4 | 35_microweb1.31.zip | 1.234 |
|
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
value of "06"...
-
Lets say the query displays , , and
. And lets say that for every record in the table having an
value of "06", I would also like to know if there
|
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 0
Now I need to generate the following monthly records using the above
table:
|
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 contains the other information.
it is set 1 to 1 in the relationships.
simplify if I can
| |
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
details on the same line e.g. B1-Title, B1-Initials, B1-Surname,
B2-Title, B2-Initials, B2-Surname, etc.
all linked to my main borrower table via an unique account number.
My 1st append query matches which account numbers are new to the main...
|
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 tblmain
but now I need to have them enter data each day for each student
so I have a new table tbldata that has TimeStart, TimeEnd
how can I make a list of students in a subform like I have now
created from tblmain, and filtered(so far so...
|
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 insert command is
placing 2 or 3 records into the table. The 'extra' records, have the
same data as the previous insert incident, (except for the timestamp).
Here is an example. Follow the values of the 'Search String' field:
|
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:
SELECT @SQLString = N'INSERT INTO TMP_UR_Randoms(Admit_DOCID,
Client_ID, SelectDate, SelectType,RecordChosen)'
SELECT @SQLString = @SQLString + N'(SELECT TOP ' + @RequFilesST + '
Admit_DOCID, Client_ID, SelectDate, SelectType, RecordChosen...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |