I have a database (datatrek.mdb) with a table named DATA.
The table has a date/time field [DatumTimeStamp] with default
value = Now(). It has 100 records in it entered over a 50-minute
period.
I would like the query to display 100 records with a new, calculated
field showing timelapse between time of record entry of current record
and time of entry of previous record. For the first record in the
dynaset, I'll settle for a value = 30 seconds. For the last 99 records
in the dynaset, I want to see the ACTUAL time-diffs between the
current and prior record.
Can I make a query do that somehow? 9 2804
For what its worth, I am hoping that a query can be created
to do what I've described in order to avoid an additional data
field in the table to house the absolute timelapse data.
MLH wrote: I have a database (datatrek.mdb) with a table named DATA. The table has a date/time field [DatumTimeStamp] with default value = Now(). It has 100 records in it entered over a 50-minute period.
I would like the query to display 100 records with a new, calculated field showing timelapse between time of record entry of current record and time of entry of previous record. For the first record in the dynaset, I'll settle for a value = 30 seconds. For the last 99 records in the dynaset, I want to see the ACTUAL time-diffs between the current and prior record.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Perhaps:
SELECT DatumTimeStamp,
DateDiff("s", (SELECT Max(DatumTimeStamp)
FROM [Data]
WHERE DatumTimeStamp < t.DatumTimeStamp),
DatumTimeStamp) As SecondsTimeLapse
FROM [Data] As t
You could also use the DMax() function instead of the subquery.
See the Access Help articles on DateDiff() and DMax() for more info.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQjONx4echKqOuFEgEQKMBQCg9ouDLbjDIhcoH2CAqwAS6E VYfgoAoL7U
QkLQpxT3afDjQ44W/S/vxaKn
=RGfs
-----END PGP SIGNATURE-----
Hey! That worked! How in the heck did you do that, man?
You're a genius!
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Perhaps:
SELECT DatumTimeStamp, DateDiff("s", (SELECT Max(DatumTimeStamp) FROM [Data] WHERE DatumTimeStamp < t.DatumTimeStamp), DatumTimeStamp) As SecondsTimeLapse
FROM [Data] As t
You could also use the DMax() function instead of the subquery.
See the Access Help articles on DateDiff() and DMax() for more info.
MLH wrote: Hey! That worked! How in the heck did you do that, man? You're a genius!
I'd like to take credit for it, but I devised it based on info in a
Query Examples db provided by Microsoft. http://www.microsoft.com/downloads/d...displaylang=en
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
MLH <CR**@NorthState.net> wrote in message news:<ak********************************@4ax.com>. .. I have a database (datatrek.mdb) with a table named DATA. The table has a date/time field [DatumTimeStamp] with default value = Now(). It has 100 records in it entered over a 50-minute period.
I would like the query to display 100 records with a new, calculated field showing timelapse between time of record entry of current record and time of entry of previous record. For the first record in the dynaset, I'll settle for a value = 30 seconds. For the last 99 records in the dynaset, I want to see the ACTUAL time-diffs between the current and prior record.
Can I make a query do that somehow?
This can be done. Depends on what you consider the "previous" record.
You can use a subquery such as the following if you're comparing based
on date.
SELECT *, DateDiff("s", (SELECT TOP 1 DatumTimeStamp FROM DATA WHERE
DatumTimeStamp < D.DatumTimeStamp ORDER BY DatumTimeStamp ASC),
D.DatumTimeStamp)
FROM DATA AS D
If you want to compare based on ID values, just change the inner WHERE
clause to compare the IDs using the same idea.\
HTH,
Russell Sinclair
Could the SQL be taken one step further to never show more than 60
in the [SecondsTimeLapse] field of the query? In other words, any
value greater than 60 calculated by the DateDiff expression would be
shown simply as 60. Wanna take a stab at that?
Well, I tried this. It worked. I'm happy.
SELECT t.DatumTimeStamp AS Expr1, IIf(DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])>60,60,DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])) AS SecondsTimeLapse
FROM tblDataTESTING AS t;
In the final analysis, this gave me PRECISELY what I needed...
SELECT t.DatumTimeStamp AS Expr1, IIf(DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])>60 or IsNull(DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])),60,DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])) AS SecondsTimeLapse
FROM tblDataTESTING AS t;
Thx again, Mr Foster.
MLH wrote: In the final analysis, this gave me PRECISELY what I needed...
< snip > Thx again, Mr Foster.
You're welcome.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mm nn |
last post by:
Hi,
I want to create a table like this:
ID Autonum
Datefld Date
Cat Text
Itm Text
tCount Number
|
by: Wilder |
last post by:
I'm trying to update a field in one table with the minimum values of
the field in another table. The two tables are linked via a common
field. I want to populate a date field in one table with...
|
by: Glenn P. |
last post by:
Sorry, CDMA, I searched this NG on several combinations of words, but
I didn't find a relevant hit, so here's my newbie question:
I have an Access 2002 table which contains data extracted from...
|
by: rednexgfx_k |
last post by:
All,
Problem Summary: I've running about 30 make table queries via VBA in
Access 2000, and my database goes from 14,000k to over 2,000,000k. In
addition, the longer the procedure runs, the...
|
by: Dixie |
last post by:
How can I programatically, take some Date/Time fields present in a table in
the current database and change their type to text?
dixie
|
by: x |
last post by:
hi
i am a pilot by profession. i want to create a database of my logbook
using ms access 2002. i am facing a problem regarding the format of
time field. when i select "Data/Time" data type for my...
|
by: laurentc |
last post by:
Dear all,
I have several tables based on exactly the same fields
(Key/Date/Price1/Price2).
I do some statistics on the prices.
However, as I have many different tables (the tables are...
|
by: sesling |
last post by:
I need some help with a date/time field. We run several processing jobs each day. The start and end times are stored in separate columns. The data is stored as date and time. I want to run a...
|
by: debi.robarts |
last post by:
Ok, in my database I have something like this:
Date One
# of Days to Next Date
These calculate a field "Date Two."
Because "Date Two" is an expression (calculated by the form), I can't
set...
|
by: tomash |
last post by:
Hi!
I ve got two tables in Access 2007.
I want to update a field of DataTable from another table, DataSumTable when two of their fields equals.
( the fields : Name and Period)
I tried this...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| | |