Trouble Joining On Datetime

Apr 14, 2008

Hello -

I have a table that looks like this:
Code:ID Station DateTime Value 1 ABQ 10/8/2005 1:00 am 102 ABQ 10/8/2005 2:00 am 203 ABQ 10/8/2005 3:00 am 254 ABQ 10/8/2005 4:00 am 5...
I am trying to build a query that, for each record, gives me the values for the previous 2 hours.

So my goal would be a query that returns:
Code:ID Station DateTime Value ValueT-1 ValueT-21 ABQ 10/8/2005 1:00 am 10 Null Null2 ABQ 10/8/2005 2:00 am 20 10 Null3 ABQ 10/8/2005 3:00 am 25 20 104 ABQ 10/8/2005 4:00 am 5 25 20...

I created a table (NewTable) that, for each record, has the DateTime, DateTimeT-1, and DateTimeT-2. So columns in Newtable are ID, Station, DateTime, Value, DateTimeT-1, DateTimeT-2 where DateTimeT-1 = dateadd("h",-1,DateTime) and DateTimeT-2 = dateadd("h",-2,DateTime).

I then joined (using a left join) this new table to the original table on [NewTable].[DateTimeT-1] = [OldTable].[DateTimeT].
so code is
Code:select [NewTable].ID, [NewTable].Station, [NewTable].DateTime, [NewTable].Value, [OldTable].DateTime, [OldTable].Value AS ValueT-1from NewTable left join ON [NewTable].[DateTimeT-1] = [OldTable].[DateTimeT]

The output does not pull all the right records. Some of the records have Null values for ValueT-1 when the datetimeT-1 is in OldTable. So for some reason the join doesn't seem to be working.

Hopefully this is clear. Any thoughts? Help is very much appreciated!

Thank you!

View Replies


ADVERTISEMENT

Time From Datetime

May 20, 2005

Hi! This is my first question here.

I want to make query where I want to show data only from time1 to time2 (for a month).

I want to make this in Access because I need Forms.

I made this on the SQL Server but I had to change the time limits in the code what I don't like. How to make this in Access SQL?

On the SQL server it looked like this:

SELECT * FROM TimeSample
WHERE TimeVal - CAST(FLOOR(CAST(TimeVal AS float)) AS datetime) > '10:00' AND
TimeVal - CAST(FLOOR(CAST(TimeVal AS float)) AS datetime) < '17:00'

Any ideas?

Thanks, Bob.

View 3 Replies View Related

Convert To Datetime And Right()

Nov 14, 2006

Hey Guys,

Having some trouble doing a couple of things using both Data Definition Language and a Right() Query.

What I am trying to do is convert this field:
August 17, 2006 3:56 PM
into this
15:56:00

Using this:
Right([Travel Date/Time To],InStr([Travel Date/Time To],",")-1)

Now because the time part in my first field can vary from being 3:56 PM to 12:56 PM Right() is only getting those where the time has two digits.

I tried to use DDL to convert my field to DATETIME but cannot convert two columns in one SQL statement.

Can anyone help me out with this? Sorry if the details are sketchy but I'm being kicked out of the office (after 5:00pm you see!).

Cheers.

View 1 Replies View Related

Subtract TIME From DATETIME

Mar 7, 2008

I'm sure this is simple but my brain is mushy this morning!

I have two datetime fields ADMISSION and DISCHARGE with values such as 03/02/2008 15:00. How do I convert these to dates only? I don't want to just *format* them as dates, which I can do. In this example I would want to convert that date to 03/02/2008 (or 03/02/2008 00:00)

It's an idiosyncrasy of the way the NHS calculates hospital length of stay. Our previous IT system had dates and times in separate fields so I could just ignore the time field and work out length of stay based on dates only. However, our new system returns a combined datetime.

Patient A 03/02/2008 00:15 to 03/02/2008 23:45 = 0 days
but
Patient B 03/02/2008 23:45 to 04/02/2008 00:15 = 1 day

Basically, you count a day if there's a date change, even if that was only half an hour (or even a few minutes) either side of midnight, but you DON'T count a day if there was no date change, even if that was almost 24 hours.

So formatting them as dd/mm/yyyy wont work ,as I will still have partial days when I subtract one from the other and INT([DISCHARGE]-[ADMISSION]) wont always work either as it would calculate 0 for patient B.

Help!

View 2 Replies View Related

Converting Text To Datetime

Apr 21, 2008

Is it possible to convert the text field that comes in this form:

:80421

to the following datetime format: MM/DD/YY 12:00:00AM

Please note that the text field contains a colon at the beginning. The number 8 represents a year (2008), the 04 represents a month (April) and the last two characters are days in the month (21). The converted field should look like:

04/21/08 12:00:00AM

Thank you.
Peter

View 14 Replies View Related

Modules & VBA :: String To DateTime - AM / PM Missing

Oct 10, 2013

I have a form which has a text box with date and a text box with a time. DD/MM/YYYY AND HH:NN:SS

In vba I have declared A as a date and done the following

A=Format([Textbox1] & " " & [Textbox2],"dd/mm/yyyy hh:nn:ss AM/PM")
msgbox (A)

msgbox shows everything but the AM/PM

Now I need need to pass this date to excel to do a vlookup which works if I do the following

A=#03/05/2013 11:26:00 AM#

but it wont work if I grab the date and time from the access form, I think it is because the AM/PM is missing.

View 13 Replies View Related

Conditional Formatting On DateTime Field

May 6, 2015

I have a form that pulls in open project information that has a datetime field called "Duetime". What I'm attempting to do is that when this datetime field is less than 1 hour away, to turn the field background orange. Also, if less than 30 minutes to actually being past due, then it would be red.

View 3 Replies View Related

Query Datetime Field And Grouping By Date Only

Aug 28, 2007

I'm losing my mind on this one. Here is my situation... I receive a daily excel sheet with these fields. I would like to import this workfile into access and would like to manipulate it anyway I want. The problem I'm coming into is that I can't collapse/group the datetime field into just the date when I run a query. I would like to be able to run a query on any date range the client registered, a query on any and all the unique dates the client purchased something, all the unique clients, etc. Here is a sample

Sales Name - Sales # - Client Name - Client # - Registered Dt - Purchased Dt
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 18:22 - 8/4/2007 10:21
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 18:22 - 8/5/2007 18:20
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 18:22 - 8/6/2007 10:21
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 18:22 - 8/6/2007 13:28
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 18:22 - 8/6/2007 13:28
Paul, John - 273 - Kelly, Maria - 2252 - 8/7/2007 01:22 - 8/9/2007 05:46

I would like it to show...

Sales Name - Sales # - Client Name - Client # - Registered Dt - Purchased Dt
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 - 8/4/2007
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 - 8/5/2007
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 - 8/6/2007
Paul, John - 273 - Kelly, Maria - 2252 - 8/7/2007 - 8/9/2007

and a different query like ( the purchase date doesn't matter here)...

Sales Name - Sales # - Client Name - Client # - Registered Dt - Purchased Dt
Paul, John - 273 - Kelly, Maria - 2252 - 7/26/2007 - 8/4/2007
Paul, John - 273 - Kelly, Maria - 2252 - 8/7/2007 - 8/9/2007

I read in other places to change the format, input mask, convert, char, etc. but nothing. Please tell me exactly what to do. I don't care if the time changes to midnight or 0:00:00. I will owe you my first born child.

View 6 Replies View Related

Modules & VBA :: Setting DateTime Control Default Value

Nov 19, 2014

I am having an issue setting an instantiated forms' control. I am having RemDate ("Date") and RemTime ("Time") TextBox; so far the date textbox shows 1/1/1988 12:00 AM (the visible value is the time only) and the Time textbox doesn't show anything.

Code:
Set frm = New Form_ReminderAssigneesFrm
frm.RecordSource = "Select * from ReminderAssignees Where RemID = " & Parent.RemID
frm.RemID.DefaultValue = Parent.RemID
With SetRS(frm.RecordSource)
If Not .EOF Then
frm.RemDate.DefaultValue = FormatDateTime(.Fields("RemDate"), vbShortDate)

[Code] ....

View 2 Replies View Related

Queries :: Sorting Date From DateTime Field

Jan 27, 2015

I have a field on a table that is a DateTime format and it needs to be that way. I am trying to query that table for all the dates to use in a combobox but I only wat the date not the time. The problem is when I format the field to just date I can't sort it anymore as a date and I can't group them. I still get multiple lines in my combobox because there multiple times for the same day. what is the proper way in a query to extract just the date from a field and still sort it as date ie 1/12/2015 is greater than 12/15/2014?

View 8 Replies View Related

Reports :: Displaying Time Only In Datetime Field

Dec 3, 2013

I have a report that shows a datetime field and I would like to show only the time portion of the field on my report. Is there a way for me to do that?

View 2 Replies View Related

Queries :: Select Record With Nearest Datetime?

Aug 6, 2015

I would like to add fields from one table to another based on matching datetime codes.

Most data are in the table 'metadata' (information on sound recordings), and i want to add lat long fields from a large table of GPS points 'gpsData'. Each record in the metadata table has start and end datetime fields - i want to a add lat and long that matches the start time and a lat and long that matches the end time (so four fields to metadata).

My approach has been to try this with two separate select queries (i.e. one for adding the start locations and one for adding the end locations), with the intention of then combining these two outputs in a single table.

When i try a simple select query though I can see that:

a) there are no matching time codes for some records, because although the hh:mm:ss look the same there are differences in the lesser decimal places of the datetime serial numbers. I have tried using the round function on the datetime fields of both tables but this doesn't fix it (I don't understand why not).

b) there are some duplicates because there are sometimes more than one GPS point for each second, and the metadata times are given to second precision (so some metadata records get two entries in the query result).

How can I have the query select the gpsData record with the nearest datetime stamp to that in the metadata table's start time field? The respective field names are UTC and StartUTC. Can i do the same for the end times simultaneously or should i do this separately?

View 14 Replies View Related

DateTime Period Between Last Record In Table And Given Time Interval

Jul 5, 2005

HI all,
I am still new in Access databases :o

I have a table with 'General Date' column. So I have to create query wich extracts records between Last record (via Date field) and 'for example' 10 days before. But Last record in Date column may differ from Now().

When this is done I have create calculations with extracted records using agregate functions.

I'm trying to use Last function for Criteria putting it into Date field and substracting with -10 (for 10 days) but it doesn't work.

Please help! :confused:

View 7 Replies View Related

Queries :: Change Time Portion Of Datetime Field In Update Query?

Sep 12, 2013

I have some incorrect time entries in a column that I need to fix with an update query.

So, 04/11/2013 08:00:00 needs to be changed to 04/11/2013 09:00:00

View 5 Replies View Related

Tables :: DateTime - Running Pivot Queries To Excel To Do Analysis Of Data

Aug 27, 2013

I have a larget transaction data set in access with Datetime column/filed.

I have been running pivot queries to excel to do analysis of the data but the datetime field is returning too many unique values for the pivot table to run.

What is the best way to reduce the datatime field to date only and where should this be done?

i.e. should I have a calculated field that trims datetime or should I set someohting up in Powerpivot?

View 7 Replies View Related

Modules & VBA :: DateTime Format - Update Timestamp With Todays Date When User Make Changes

Dec 25, 2013

I am new to access 2010. I have a table called "Forecasts", and I wish to update the timestamp with todays date, whenever the user makes a change to the qty of goods forecasted.

I have been researching online for the solution to the correct format to datetime, but it doesnt seem to work.

Code:
Dim todayDate As Date
todayDate = Date
Dim sqlString As String
sqlString = "UPDATE [Forecasts] " & _

[Code] .....

The messagebox shows:

UPDATE [Forecast] SET Branch_Plant=123, Item_Number_Short='222', Description='AAA', UOM='EA', Estimated_Cost=123, Requesting_Business_Unit='AAA', End_Customer='CCC', Project ='Secret', Timestamp=#26/12/2013# WHERE ID =24

Then I hit a syntax error. Whats wrong with sqlString?

View 6 Replies View Related

Joining 2 Tables

Oct 25, 2006

Hi

I have an Access database that contains 2 tables. Both of these tables have the same structure and have the same field names. So:

Table 1 Fields :

Name
Address
Telephone
Fax

Table 2 Fields :

Name
Address
Telephone
Fax

Is there a way to write a query, that will show the results of both tables in one go. (None of the information in table 1 is duplicated in table 2 - I want to show all records from both tables in one new table). So, if both tables had 3 records each, the query would return:

Name - Address - Telephone - Fax

jon-uk-12345-54321 (from Table 1)
julie-uk-21451-41541 (from Table 1)
paul-ir-98545-11241 (from Table 1)
pat-uk-99585-63362 (from Table 2)
phil-uk-99985-99631 (from Table 2)
ted-uk-44444-55555 (from Table 2)


These 2 tables need to be kept separate, so I can't copy and paste the records from Table 1 into the bottom of table 2.
The field names are the same in both tables.

Can this be done?

Many Thanks

View 1 Replies View Related

Joining Tables

Jan 2, 2007

Hi All!
I have two tables. Table Heffalump which has field "DealGroup" and other fields as well... and table 8-YTD Principal Investments whic has field "book" and other fields as well... I need to use BOOK and DEAL Group as a combination primary key to compare against table 8-YTD Principal Investments. If there is a new DEAL GROUP then append into table "8 - YTD Principal Investments"

THANKS IN ADVANCE,
B

View 2 Replies View Related

Joining Fields

Mar 31, 2008

Hi Guys,

I have a problem which I cannot figure out.

I have a table which has an ID field and also a field with data. The ID field is 'not' unique.

I need to join all of the data fields which have the same ID field into one field. So it would be ID; Data 1, Data 2...

Any ideas? I would appreciate any help you could offer!

View 7 Replies View Related

Joining Strings

Aug 23, 2005

Seems like a simple question but I am stuck.

I need to join two strings from different records in a table

table eg

ID Desc
1 blah blah
1 more blah
2 blahring
2 blah
3 and last one


I want to join all the "Desc" strings that have the same ID to get

1 blah blah more blah
2 blahring blah
3 and last one

Can anyone help?? :o

Thanks

Paul

View 1 Replies View Related

Joining Fields

Oct 4, 2005

I'm trying to create a Purchase Order Database that requires a monthly summary of all the purchase orders in that month.

Examples of the fields i'm using are: Date, Vendor, Description, Item Number, Unit Price, Quantity, Sub-total, Total, etc.

Each table is a single purchase order, and there are around 3 or so every month. What I am trying to do is create a query in which all related fields are joined, and can be viewed as a single field.

For example:

Field 1 is DATE for Purchase Order (PO) 1, 2, and 3.

What I want to do is join all entries in DATE from PO1, PO2, and PO3 in a single query.

I want it to look like:

[DATE]
PO1......
PO2......
PO3......

I've tried several approaches to this problem, but they all have the same end result. It creates a seperate field for each table:

[PO1-DATE][PO2-DATE][PO3-DATE]



Any suggestions?

View 2 Replies View Related

Joining Queries

Aug 23, 2006

I have two tables. One stores details of all money travelling from A to B, one from B to A.
I have created queries 'qry_A_to_B' and 'qry_B_to_A' to get each set of information.
Since there are User IDs in each table that don't appear in the other, I'm using the following two queries to return all the TO and FROM values. By using both LEFT joins, I appear to be getting all entries.

'A to B data
'------------
SELECT
[qry_A_to_B Yearly].ABUserID,
[qry_A to B Yearly].ABMonth_of_Year,
[qry_A to B Yearly].ABYearly_Sum,
[qry_A to B Yearly].ABMonthly_Sum,
[qry_A to B].ABMonth
FROM
[qry_A to B Yearly]
LEFT JOIN [qry_B to A]
ON [qry_A to B Yearly].[ABUserID] = [qry_B to A Yearly].BAUserID
GROUP BY
[qry_A to B Yearly].ABUserID,
[qry_A to B Yearly].ABMonth_of_Year,
[qry_A to B Yearly].ABYearly_Sum,
[qry_A to B Yearly].ABMonthly_Sum,
[qry_A to B].ABMonth;

'B to A data
'------------
SELECT
[qry_B to A Yearly].BAUserID,
[qry_B to A Yearly].BAMonth_of_Year,
[qry_B to A Yearly].BAYearly_Sum,
[qry_B to A Yearly].BAMonthly_Sum,
[qry_B to A].BAMonth
FROM
[qry_B to A Yearly]
LEFT JOIN [qry_A to B]
ON [qry_A to B Yearly].[ABUserID] = [qry_B to A Yearly].BAUserID
GROUP BY
[qry_B to A Yearly].BAUserID,
[qry_B to A Yearly].BAMonth_of_Year,
[qry_B to A Yearly].BAYearly_Sum,
[qry_B to A Yearly].BAMonthly_Sum,
[qry_B to A].BAMonth;

How can I join these two, to provide a list of ALL information, from all ten columns, regardless of whether or not someone has both a TO and FROM value? i.e.
If they only have a TO entry, I want to see it; the other five columns would be blank.
If they only have a FROM entry I want to see it; the other five columns would be blank.
If they have both, I want them to line up on one line.

However I try to phrase the query, I seem to miss at least some of the information from one or both tables.

View 9 Replies View Related

Joining Tables

Feb 16, 2007

I am building a simple task tracker to keep a record of tasks being passed back and forth between our team. The schema is fairly simple as illustrated in the image below.http://img2.freeimagehosting.net/uploads/f4f3a05c21.gifI want a recordset as follows out of this database (+/- few columns. But these are the most essential ones needed) -ixProject | Project.sTitle | ixTask | Task.sTitle | TaskHistory.dtEntry | sStatus | sEmployeeAssignor | sEmployeeAssigneeThis is basically a recordset of the history of the task (who assigned task to whom) and the status (assigned, resolved, closed). I can get the query to return the user id (ixEmployee) without any problems. But to display this in the interface I will need the employees name (sUsername).I tried the following query -SELECT Employee.sUsername AS sEmployeeAssignor, Employee.sUsername AS sEmployeeAssignee, Project.sTitle AS sProjectTitle, Task.sTitle, TaskHistory.dtEntry, TaskHistory.sDescription FROM(((Project INNER JOIN Task ON Project.ixProject = Task.ixProject) INNER JOIN (Employee INNER JOIN TaskHistory ON Employee.ixEmployee = TaskHistory.ixEmployeeAssignor)ON Task.ixTask = TaskHistory.ixTask)INNER JOIN Employee ON Employee.ixEmployee = TaskHistory.ixEmployeeAssignee <<< THIS IS THE PROBLEM LINE)WHERE (SELECT LAST(TaskHistory.ixEmployeeAssignee) FROM TaskHistory) = 1ORDER BY TaskHistory.ixTask, TaskHistory.ixTaskHistoryThis is the error I get -Join expression not supported.State:S1000,Native:-3530,Origin:[Microsoft][ODBC Microsoft Access Driver]Can someone explain how I can solve this problem? I am currently running two queries - one to retrieve the usernames, and the other to retrieve the history with the user id's - and replacing the user id's with usernames when displaying the records, but would like to have a cleaner solution.

View 2 Replies View Related

Joining Only For 1 Record...

May 30, 2007

This gets even more confusing as I go.


Two tables again needing to be joined. But only need to fill the data in the first line.... yes, Pain in the ARSE> here's a sample.

PAYLINES TABLE
EMPLOYEE --------- DATE -------- Paytype
121614000 -------- 12/31/2007 --- 300
121614000 -------- 12/31/2007 --- 122
121614000 -------- 12/31/2007 --- 100
121614000 -------- 12/23/2007 --- 100

TAXTABLE
EMPLOYEE --------- DATE -------- CPP ---- EI
121614000 -------- 12/31/2007 --- 1.23 --- 2.35
121614000 -------- 12/23/2007 --- 2.32 --- 1.35


The end Query I need is

EMPLOYEE --------- DATE -------- Paytype --- CPP ---- EI
121614000 -------- 12/31/2007 --- 300 ------- 1.23 ---- 2.35
121614000 -------- 12/31/2007 --- 122 ------- NULL ---- NULL
121614000 -------- 12/31/2007 --- 100 ------- NULL ---- NULL
121614000 -------- 12/23/2007 --- 100 ------- 2.32 ---- 1.35

The TAXTABLE only needs to assign it's data to the FIRST row of the resulting query

View 3 Replies View Related

Joining 2 Tables

Jan 30, 2008

Hello! I need to join 2 tables, 1 table with all of the fields, and another with just 2.

The link between the 2 tables is an ID field in field 2 wich is long integer.

The problem is, the ID field in table 1 that correlates to the ID field in table 2, is in the datatype text.

I cant change the datatype of the field in table 1 because it is a linked table to a txt file. And some of the values in there are dashes, indicating no ID. (not sure why).

So, is there ANY way to link the2 tables with the 2 different datatypes

Thanks in advance!

View 5 Replies View Related

Joining 2 Recordsets

Feb 17, 2005

I have two tables in my database. one is linked to a Client.txt and the other is tblNewClient.
the idea is that this database is a portable version of the actual database, meaning that it will be operating on its own without a connection to the actual back end.

Now the problem is when a new customer is added, i want it to add itself to the tblNewClient.
but when i go into my Find CUSTOMERS FORM i need to be able to search threw both tables.

i want to creat somthing like a union query but in vba.
I figure i need to have 2 recordsets in vba. one for each table and then i need to have a 3rd recordset wich will hold all the info.
im not sure how to copy a whole recordset and set to another table.

Im thinking of somthing like

set RsAll = RsClient & RsNewClient

This obviously does not work but it is what i want to accomplish ,and i want the Rsall to be an actual table and not a public Recordset

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved