Queries :: Comparison Of Dates Between Lines

Oct 22, 2013

I am having some "fun" at the moment trying to work out how to compare two times on different rows. The current setup I have is:

StartDTM EndDTM VisitID
09:00:00 10:00:00 1
11:00:00 12:00:00 2
12:15:00 13:00:00 3

etc etc...

I have found a SQL Query I have tried to use, however I am having no joy. The query is such:

WITH rows AS
(
SELECT *, ROW_NUMBER() OVER (ORDER BY VisitID) AS rn
FROM Data
)
SELECT DATEDIFF("n", mc.EndDTM, mp.StartDTM)
FROM rows mc
JOIN rows mp
ON mc.rn = mp.rn - 1

View Replies


ADVERTISEMENT

Queries :: SQL Text Field Comparison

Dec 13, 2013

I am comparing the columns in two tables in a JOIN to see if there are differences. The columns, COL3 and COL4, are "Text" fields. They are declared as:

Field Size = 255
Default Value = "" (an empty string)
Required = No
Allow Zero Length = Yes
Indexed = No

I use the SQL comparator <> in my test... so ...

Code:
SELECT * FROM
Table_A AS Tgt
LEFT JOIN Table_B AS Src
ON (Src.Col1 = Tgt.Col1 AND Src.Col2 = Tgt.Col2)
WHERE Src.Col3 <> Tgt.Col3 OR Src.Col4 <> Tgt.Col4

I expected that where Src.Col3 was set to 0 (the string character zero) and Tgt.Col3 was set to the default of "" (a zero length string) that the query would return that row? It does not however? No doubt this is tied in with the old NULL string and Empty string chestnut?What is the best way to compare "text" fields in Access.

View 8 Replies View Related

Queries :: Numeric Comparison And Null Values

Sep 24, 2013

I have a form with a textbox, where one inputs a number and then I run a query with the form criteria. The query is

Code:
Select Blah blah from dbo_temp where A>textbox value OR B>textbox value OR C>textbox value OR D>textbox value

The columns which are linked to the textbox some times contain null values. So, A, B, C, D columns do contain null values.

The expression in the "Criteria" column of Columns A, B, C, D (all on different lines - to make sure OR criteria is fullfilled) is as follows

Code:
>IIf(IsNull([Forms]![MainForm]![Criteria]),-100,[Forms]![MainForm]![Criteria])

I've put in -100 as an arbitrary never possible number. Obviously, this does not return Null values.

Question: How can I return both Null & Numbers when the Textbox in the form is left blank? in all the columns. Currently, I am not getting Null values

Code:
>IIf(IsNull([Forms]![MainForm]![Criteria]),SHOW ME EVERYTHING INCLUDING NULL VALUES & NON-NULL NUMBERS,[Forms]![Material Finder]![txtPS])

or in other words

If the textbox is blank, show me all the data available, else if it is not blank then show me only the values that are greater than the number entered in the textbox from within column A, B, C, D ....

View 3 Replies View Related

Queries :: Date Conversion Comparison Not Working?

Nov 8, 2013

I recently (temporarily)took over a position that uses an Access database that does not work properly, and I'm stumpped on how to fix it.

The query is supposed to pull all data where the "Date Overdue" field is less than today.

"Date Overdue" is a calculated value that pulls from the field "Date Input", which is in a text format (DDMMMYY) Such as 03NOV13. It is 8 days after the date input.

It prints out like this: "Monday, November 11, 2013" which is 8 days after the 3rd.

"Date Overdue" is set to this value:

Code:

DATE OVERDUE: DateValue(Left([DATEINPUT],2) & "/" & Mid([DATEINPUT],3,3) & "/" & Right([DATEINPUT],2))+8
"Date Overdue" has the criteria "<DateValue(CDate(Now()))"

I'm not going to go into all the different steps I've taken to try and get this to work because I've toyed with it a lot..

The output that I always seem to get is a mixture of all records that are available, before and after today's date, I just wanted those that are less than today.

I suspect that the date values that are shown in the query aren't true dates because when I click on the filter button it gives me this error:

"Syntax error (missing operator) in query expression 'DATE OVERDUE' "

NOTE: I'd like to add that this is just a regular Select query.

Code:
SELECT DateValue(Left([DATEINPUT],2) & "/" & Mid([DATEINPUT],3,3) & "/" & Right([DATEINPUT],2))
AS [PRODUCT END PERIOD], DateValue(Left([DATEINPUT],2) & "/" & Mid([DATEINPUT],3,3) & "/" & Right([DATEINPUT],2))+8
AS [DATE OVERDUE], [QBR ON EQUIP].DATEINPUT, [ALL ERRORS].[ERROR STATUS],

[Code] .....

View 1 Replies View Related

Queries :: IIF Statement With Comparison Operators In True And False Parts

Oct 2, 2014

I have a report where my customer wants to be able to input a value and then be able to select whether the report shows values above or below that value. I have a combo box that has 2 values (1=Less than or equal to, 2=greater than or equal to). There is a text box where he inputs the rate to compare against (e.g. $75). When he hits submit, the application stores the values of the combo box and text box into global variable and then I have a public function that can be used to retrieve the values. GetHRate() gets the value to compare against and GetHRateCompare() gets the value to indicate <=(1) or >=(2).

In my query for criteria for rate I have this expression:
IIf(GetHRateCompare()=1,"'<=",">=") & GetHrate()

I've tried every combination of double quotes, single quotes, no quotes moving the GetHRate inside the IIf statement and nothing seems to work.

If I just hardcode <=GetHrate() into the criteria it works perfect but that does not achieve my goal of letting him select over/under at run time. Here's the full query:

SELECT qryCustomers_AverageTimeByScheduleID.ServiceName, qryCustomers_AverageTimeByScheduleID.ScheduleID, qryCustomers_AverageTimeByScheduleID.SumOfTotalTim e, qryCustomers_AverageTimeByScheduleID.PropertyID, qryCustomers_AverageTimeByScheduleID.PropertyName, qryCustomers_AverageTimeByScheduleID.MonthCount, qryCustomers_AverageTimeByScheduleID.AverageTime,

[Code] ....

View 2 Replies View Related

Queries :: Comparison To Previous Month Or Week Depending On The Report

Dec 31, 2014

I have a query based form i use to gather data to generate a report. I have 2 forms Form A is where users open all reports from. On form A i have 2 unbound fields "Report Start Date" and "Report End Date" my queries us these from Form A as the criteria for the queries. I have like 30 reports using this method and it works great. I am now building 2 new reports, a monthly and a weekly report. These reports required and data entry point so i built "Form B"

I created my tables for these reports and went through and created the records. So when a manager needs to enter data for any given report they would us "Report Start Date" to identify what record they want to work with, so if they want to enter data for the December report the would select 12/01/2014 and then open "Form B". This works great and the report looks as good as any Access report can.

Now they are asking to add to "Form B" a comparison to the previous month or week depending on the report. for example:

This month we did 250 units
Last month we did 300 units
so we did 15% less
"Yes my math is not exact"

They don't need to see last months data but i need a way to query the previous record to compare the data

This is the criteria code i use in the query that "Form B" is based on.

Code:
[Forms]![Form A]![Report_Start_Date]

I am pulling up the 12/01/2014 in "Form B" but need the 11/01/2014 record floating behind to compare data.

How can i use the same setup but pull a 2nd record? I am thinking i can use a 2nd query but with different criteria.

View 3 Replies View Related

Queries :: Updating Lines In A Query

Sep 26, 2013

I have created a query which is based on 2 tables.I now want to use the query to update content as needed in one of the tablesWhen I try to do this it says, Operation must use an updateable query..I used the update feature but it still says must be created in updateable query.

View 4 Replies View Related

Queries :: Multiple Lines In A Field?

Jan 8, 2014

I've exported some data which has 3-4 address line within the same field which is very odd.

The row has all the usual data, but when I look at the data in datasheet view the adresss line 1 shows only but when I click into the field and press down, more address info comes up. Is there any way to have this on one row within the field rather than multiple.

A bit like in Excel when you Alt+Tab in a cell it drops down but is the same cell, well this exactly like that in Access 2003.

View 1 Replies View Related

Queries :: Possible To Split One Table Into Multiple Lines?

Oct 27, 2014

My boss made a satisfaction database that tracks satisfaction in 2 ways, so we have:

Table

ID
SatisfactionAType
SatisfactionAScore
SatisfactionBType
SatisfactionBScore

I'd like to make a query that would split these into two lines, one for A, one for B and then export it to excel.

View 4 Replies View Related

Queries :: Sums Up All Previous Lines In A Field

Feb 9, 2014

I have a query that displays the difference between the number of scanned and processed invoices for each date (invoices scanned minus processed). Now I would like to make a query that for each date based on this shows the total backlog accumulated.

Example table:

The first column contains the date, and the second number of invoices scanned minus invoices processed.

2014-01-02 53
2014-01-03 -15
2014-01-04 24

Would it be possible somehow to make a query that for each lines shows the complete sum of all previous lines?

Based on the above data the result should be:

2014-01-02 53
2014-01-03 38
2014-01-04 62

Or would I have to write some VBA code to create some kind of temp table?

View 2 Replies View Related

Queries :: Calculate Expiry Dates Of Training Courses - Due Dates Not Shown

Aug 28, 2013

I have built a query to calculate the expiry dates of training courses but I am trying to input a criteria so that only dates within 90 days of todays date show. I am using Date()<90 but it doesn't return the correct information. What the criteria should be for this?

View 1 Replies View Related

Queries :: Access 2007 - Select All Dates Between Two Dates?

Apr 9, 2015

I have a table of records, which has within it two date fields (effectively, a 'start' and 'end' date for that particular record)

I now need to create a query to perform a calculation for each date between the 'start' date and the 'end' date

So the first step (as I see it anyway) is to try to create a query which will give me each date between the two reference dates, in the hope that I can then JOIN that onto another query to perform the necessary calculation for each of the returned dates.

Is there a way to do this?

So basically, if for a particular record, the 'start' date is 01-Apr-2015 and the 'end' date is 09-Apr-2015, can I produce a dataset of 9 records as follows :01-Apr-2015

02-Apr-2015
03-Apr-2015
04-Apr-2015
05-Apr-2015
06-Apr-2015
07-Apr-2015
08-Apr-2015
09-Apr-2015

(The *obvious* solution would be to create a separate table of dates, from which I could just SELECT DISTINCT <Date> Between #04/01/2015# And #04/09/2015# - but that seems like a dreadful waste of space, if that table is only required to generate the above? And it would have to cover all possible options; so it would either have to be massive, and contain every possible date - ever! - or maintained, adding new dates as necessary when they are required. Seems horribly inefficient!)

Is it possible to just select each date between the two reference dates? Or can you only query something which exists somewhere in a table?

View 4 Replies View Related

Queries :: Can Copy And Paste Lines From Email And Display Properly

Mar 20, 2014

This may not be the proper forum, but I don't know where else to put the question. Table1 is a mysql table with a memo field which is set up in a form as a rich text field. I can copy and paste lines from an email and they display properly. Viewing that field in the underlying table they have <br />, etc.

Table2 is another mysql table, containing a memo field in plain text. I need to append the records in table2 to table1. The memo field gets appended as one long run-on sentence with no LF/Cr or <br />. How can I programatically convert the plain text to rich text either before, during or after the append?

View 2 Replies View Related

Queries :: Counting Records Returning Load Of Lines Of Repeated Data?

Oct 11, 2014

I have created a query that is designed to return a count of how many records there are in various tables. There are 10 expressions in all, so when it is run I am expecting to see one row of data with each field populated with the number of records.

It does do this, but the data is repeated over line after line (see the attached picture)

View 4 Replies View Related

Queries :: Count Dates Between Dates In Two Tables

Jul 8, 2014

I have two tables with dates. Between (!) every two following dates in table1, I want to know the number of dates in table2. How do I write an SQL query for this? The tables I have are up to a few hundred records in table 1 and a few thousand records in table2. So to prevent that this takes hours I need a fast query.

To explain the query I need, for example:
table1
01/01/2014
15/01/2014
17/01/2014
30/01/2014

table2
01/01/2014
02/01/2014
05/01/2014
17/01/2014
18/01/2014
20/01/2014
21/01/2014
25/01/2014

So the answer of the query would be 2,0,4.

Explanation:
Between 01/01/2014 and 15/01/2014 in table 1 there are 2 dates in table2 (01/01/2014 is not included between the dates)
Between 15/01/2014 and 17/01/2014 in table 1 there are 0 dates in table 2
Between 17/01/2014 and 30/01/2014 in table 1 there are 4 dates in table 2

View 2 Replies View Related

Queries :: Date Range Query - Return Lines Where Field Is Blank In Table

Aug 15, 2013

I have a single table with customer information, one of the fields is a date field "LastContacted".

I'm creating a search form with 2 date fields (txtDate1 & txtDate2) to search a date range of the LastContacted field, and I need to write this into the query that the search form uses.

I have written this using Nz so that it can still return results if the search boxes are left blank:

Between Nz([Forms]![frm_AdvancedSearch]![txtDate1],#01/01/1989#) And Nz([Forms]![frm_AdvancedSearch]![txtDate2],#01/01/2999#)

This seems to work and it returns lines from the table where there is a date entered. However some of the fields in the table have no entry in the LastContacted field. How to code this query so that it also returns lines where the LastContacted field is blank in the table?

I have tried:

like "*" & (Between Nz([Forms]![frm_AdvancedSearch]![txtDate1],#01/01/1989#) And Nz([Forms]![frm_AdvancedSearch]![txtDate2],#01/01/2999#)) & "*"

but this returns errors when I try to run it.

I'm using Access 2010.

View 14 Replies View Related

Table Comparison

Feb 26, 2006

Is there a way to look at two tables to compare records and add missing records from table to the other?

Thanks!
Terry

View 3 Replies View Related

Comparison Operators.

Apr 27, 2006

I'm having difficulty coming up with a way to exlcuded a group of dates from my Query. I am trying to have a set of dates come up without the dates, between 7/1/2006 and 7/31/2006.

I've tried <> Between #7/1/2006# And #7/31/2006#, and a few others with quotes and such. Any help would be greatly appreciated.

View 1 Replies View Related

Date Comparison

Jun 13, 2005

Hey all,

I've got to show records from a table that are 45 days old or newer.. im not quite sure how to do this in SQL ...

Select field from table where date > (todaysdate-45).. as you can see..clueless lol any help is _greatly_ appreciated

View 3 Replies View Related

Queries :: Changing Dates In A Group Of Queries

Jul 21, 2013

I have written a large number of queries to gather data for a quarterly monitoring form. How do I replace the dates to update them for next quarter.For example I have written a query which counts the number of new members who started in the period 01/04/2013 to 31/07/2013. How can I change this (and the other 200 queries) without opening them all individually and manually altering it. Is there an Access equivalent of Word's Find and Replace?By the way I am using Access 2000.

View 11 Replies View Related

Text To Date Comparison

Jan 24, 2007

Hi all- I'm creating an update query.I have a field [dateLastEdit] that is stored as text, I have to compare it to a date entered on a form by user [date_from] (I need to select all dates greater than this) but I'm running into problems:when I use date_from in text or date format and compare it to dateLastEdit in text format the comparison is made in numeric order(so 12/02/2006 is selected as well as 12/02/2005 when date_from is 12/01/2006)SELECT PTSData.LastEditDateFROM PTSDataWHERE (((PTSData.LastEditDate)>=[Forms]![chMgmt_frm]![date_from]));when I use date_from in date format and compare it to dateLastEdit converted to date format I get "expression typed incorrectly or it is too complex to be evaluated" msg.SELECT DateValue([LastEditDate]) AS Expr1FROM PTSDataWHERE (((DateValue([LastEditDate]))>=[Forms]![chMgmt_frm]![date_from]));[LastEditDate]'s format is always mm/dd/yyyy hh:mm:ss, but as text, not date data type.I've tried CDate with same results, isolating it in its own query to test it, using hardwired dates as criteria, but no joy, am I missing something obvious?forgot to add- I've used all the above with left also to select only date portion with same results

View 5 Replies View Related

Values Comparison Query

Nov 20, 2007

I really have looked everywhere

I have 2 fields and I want a query to pull out the records with a lower or equal to quantity value than the stock.

ReorderValue
3
5

Quantity
2
6

As you can see it shuold pick out the top record because its lower, I just need a way of telling it to look at each records Reorder Value

View 8 Replies View Related

DateAdd / Comparison A97 Problem

Feb 8, 2008

I'm running a query to find records over one year old. When I use Date()-"365" or DateAdd (365 days, 12 months, 4 quarters, or 1 year) the records from one year ago today come up just like they are suppose to. The problem comes in when I put the comparison operator out front.

If I put < in front of either Date() or DateAdd minus one year, I get all records from yesterday and earlier as if it is ignoring the year and only looking at the month and day. If I put > in front, I get today's records.

Date() and DateAdd by themselves are working as advertised. Things only get weird when I put < or > out front.

What am I doing wrong?

Thanks,
Forrest

View 2 Replies View Related

Complex Query And Comparison

Aug 9, 2005

I have a scheduling database that my company uses to manage our customers deliveries. We would like to make this database more intelligent by adding some logic and I am not quite sure how to proceed.

On the form frmDelivery, the user inputs all the header information for the delivery, in the subform subfrmLotInfo, they input the houses that will be delivered, the delivery date, and some other miscellaneous information.

When the user inputs the delivery date, the system should count back a number of days based on other criteria and set a build date (when we should start building the cabinets, typically 5 days before the delivery date). Then I need the database to run a query against this date and determine how many boxes we have scheduled to be built already on that day, if it exceed a certain number than I need to it to search an available date close to that date that has not exceeded our production capacity and schedule the lot for that date.

This needs to happen as well if the user changes the delivery date at a later time. Our customers change delivery dates constantly. This will help us schedule our manufacturing plant better and reduce the possiblity of scheduling more than we can actually accomodate.

I have a table tblPrdCapacity that holds how many boxes we can build on a given day. It hold Date, PrdCap (number of boxes). In the subfrmLotInfo, the field BoxesBuilt tells how many boxes will be built for that Lot.

Any info would be greatly appreciated!! I have been tasked to accomplish this as soon as possible.

Thank you!!!

View 3 Replies View Related

Simple Currency Field Comparison

Nov 22, 2005

Simple, I'm sure, but I am having one of those days...

I just need to compare two currency fields and do something if the difference is greater than one cent.

Any help with that incredibly simple expression, please? :D

View 2 Replies View Related

String And Numeric Data Comparison

Apr 19, 2006

I need to make a query to compare equality of two pieces of data, one is a 6 character fixed-length text string (where the first character can be ignored) and the other is a 4 or 5 digit number (long integer, if 4 digit number can be assumed to be 5 with a leading 0).

I do not have the ability to change the way I receive the data, they are on linked tables of different customers.

I tried using various SQL functions to convert the data in the query but they don't seem to work in Access, so I am getting "Type incorrect in the expression" errors.

How do I do this in ACCESS? I would prefer a SQL query solution to a VBA solution if possible, the data is updated VERY often and the application is already doing too much processing on the form_timer() event.

View 2 Replies View Related







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