thank you for you answer!!!
enter image description here
table is this picture
SELECT * FROM
vehicle_warning_message v
WHERE
v.capture_time >= "2023-10-03%"
AND v.capture_time <= "2023-11-03%";
enter image description here
Why can the value of 2023-11-03 be displayed, but not the value of 2023-10-03? The two values are the maximum time of the day, namely "2023-10-03 23:59:59" and "2023-11-03 23:59:59".
If your date-time column is of type string, then the expression '>= "2023-10-03%"' means to search for all values in alphabetical order greater than or equal to '2023-10-03%'. The percent sign is a symbol above which the search will not search in the ASCI table. Therefore, "2023-10-03" is not displayed.
Related
In Access I have a table, where I enter the times I began and finished work for each day. Logically, these two numbers allow you to calculate how long you worked.
In another Table I have currently four records, defining how long the lunch break has to be on a specific day, based on how long I worked that day, something like this
Minimum work time; Minimum break
0:00; 0:00
5:31; 0:15
7:01; 0:30
9:01; 1:00
In Excel I can use the Vlookup, set to work with approximate times. For example, if one day the duration was 7:42, the Vlookup would return "0:30", going to the closest lower value, 7:01, and returning 0:30.
Is there a function in the formula editor in the query window of Access to solve this problem or does Access just lack this possibility? I'm just very curious about that.
Use a subquery to look up the break time:
SELECT
TableWork.Id,
TableWork.BeginTime,
TableWork.FinishTime,
CDate(FinishTime - BeginTime) AS WorkTime,
(Select Top 1
[Minimum break]
From
TableBreak
Where
[Minimum work time] <= ([FinishTime] - [BeginTime])
Order By
[Minimum work time] Desc) AS BreakTime,
CDate([WorkTime] - [BreakTime]) AS NetTime
FROM
TableWork
ORDER BY
TableWork.Id;
If your table field data type is Date/Time then try below query.
SELECT TOP 1 format(tblST.MinBrk,"hh:mm") as [Minimum Break]
FROM tblST
WHERE (((tblST.[MinWT])<=TimeSerial(7,42,0)))
ORDER BY tblST.MinWT DESC;
If data type is Number then try below-
SELECT TOP 1 tblST2.MinBrk as [Minimum Break]
FROM tblST2
WHERE (((tblST2.[MinWT])<=7.42))
ORDER BY tblST2.MinWT DESC;
A nested query can return break time:
SELECT tblWork.WorkTime,
Format((SELECT Max(MinimumBreak) FROM tblBreaks
WHERE MinimumWorkTime<=tblWork.WorkTime), "Short Time") AS BreakTime
FROM tblWork;
or
SELECT tblWork.WorkTime,
Format((SELECT TOP 1 MinimumBreak FROM tblBreaks
WHERE MinimumWorkTime<=tblWork.WorkTime
ORDER BY MinimumBreak DESC), "Short Time") AS BreakTime
FROM tblWork;
However, both result in a non-editable dataset so this is okay for a report but not for data entry form. Use domain aggregate function expression in textbox.
DMax("MinimumBreak", "tblBreaks", "MinimumWorkTime<=#" & Me.WorkTime & "#")
I have a form called FirstInLastOut which looks as the image below.
Based on Name or badge number I want to search between two dates.
I am using the following criteria on the query:
>=[Forms]![FirstInLastOut]![StartDateEntry] And <=[Forms]![FirstInLastOut]![EndDateEntry]
This is given me results that include other months as well. Please see the query report below.
So as you can see in the image the numbers of the dates are falling with the the parameter but getting other months as well.
How can I make it so it will only select the dates between the date ranges?
SELECT FistClockInRaw.Badgenumber, FistClockInRaw.name, FistClockInRaw.lastname, FistClockInRaw.MinOfCHECKTIME, FLastClockOutRaw.MaxOfCHECKTIME, [MaxOfCHECKTIME]-[MinOfCHECKTIME] AS TotalHours, FLastClockOutRaw.QDate, FistClockInRaw.MinOfQTime, FLastClockOutRaw.MaxOfQTime, RawCompleteQuery.CHECKTIME
FROM RawCompleteQuery, FLastClockOutRaw INNER JOIN FistClockInRaw ON (FLastClockOutRaw.Badgenumber = FistClockInRaw.Badgenumber) AND (FLastClockOutRaw.name = FistClockInRaw.name) AND (FLastClockOutRaw.QDate = FistClockInRaw.QDate)
WHERE (((FistClockInRaw.name)=[Forms]![FirstInLastOut]![FirstNameEntry]) AND ((RawCompleteQuery.CHECKTIME)>=[Forms]![FirstInLastOut]![StartDateEntry] And (RawCompleteQuery.CHECKTIME)<=[Forms]![FirstInLastOut]![EndDateEntry]));
is the Query
I assume that the forms fields StartDateEntry and EndDateEntry are bound to fields of type date.
I also assume that you are only interested to compare the date part of those form fields.
So try this condition instead to assure correct date interpreting:
WHERE FistClockInRaw.name=[Forms]![FirstInLastOut]![FirstNameEntry]
AND RawCompleteQuery.CHECKTIME >= Format([Forms]![FirstInLastOut]![StartDateEntry], "\#yyyy-mm-dd\#")
AND RawCompleteQuery.CHECKTIME <= Format([Forms]![FirstInLastOut]![EndDateEntry], "\#yyyy-mm-dd\#")
A remark:
Be aware that every date field/variable always contains a time part too!
So your current logic comparing EndDateEntry with <= can cause trouble, because you would only get results of the end date having time values of 00:00:00 in the field CHECKTIME.
If any record of CHECKTIME contains the requested end date and a time part bigger then 00:00:00, it is not in the result.
To avoid that, you should use < and add one day:
And RawCompleteQuery.CHECKTIME < Format([Forms]![FirstInLastOut]![EndDateEntry] + 1, "\#yyyy-mm-dd\#")
i have a table name expected expense in which i have 4 columns name Expense_title, Amount, expense_category, date and all the 4 columns have var char type. When I try to find expense between two dates it work fine for same year, e.g. 11/27/2018 and 12/27/2018, but it doesn't get any result when I try to find expense between two years, e.g. 12/27/2018 And 01/27/2019. please help
I am trying this query
SELECT *
from expected_expense
WHERE Date BETWEEN '$start_date' AND '$end_date'
As per the comments, this is because of the varchar type.
The between operator is nothing different than doing two closed inequalities for its range limits. In your example,
between 12/27/2018 And 01/27/2019
will be changed internally to
>= 12/27/2018 and <= 01/27/2019
but these are not dates, they are text. And the second one is less than the first, so nothing will be returned. It's like asking the question: which letter comes after q but before b? None.
Either change the fields to datetime, or use conversion functions in your query.
So I have a table called dash with two columns: value and date.
I have a timestamp variable called localtime.
Both localtime and date are in yyyy-mm-dd hh-mm format.
I need to find the closest timestamp on dash, return the value.
Right now what I have doesn't work.
def convValueChecking(cursor, localtime):
cursor.execute("SELECT Value, MIN(TIMESTAMPDIFF(MINUTE, DATE, %s)) FROM dash", (localtime))
value = cursor.fetchall()
Update:
This one seems to work, the order_date > locatime is very important, otherwise it looks for the smallest negative number
cursor.execute(
"SELECT order_value, order_date FROM dashboard \
WHERE order_date > %s\
ORDER BY ABS(TIMESTAMPDIFF(MINUTE, %s, order_date))\
LIMIT 1", (localtime, localtime,))
Try replacing the SQL string with:
SELECT
value
FROM
dash
WHERE
TIMEDIFF(Date, %s) IN
(
SELECT
MIN(TIMEDIFF(Date, %s))
FROM
dash
)
MySQL syntax means you need to do SELECT then FROM and then declare the WHERE part.
TIMEDIFF works out the difference between two timestamps. TIMESTAMPDIFF works out the difference between two parts of a timestamp (eg between the months, days, seconds etc.). If you want the closest date you should use TIMEDIFF to work out the smallest difference overall.
NB. The words Value and Date also have special properties in MySQL, so you may want to change your column name.
SQLFiddle.
I have a field in a query that is checking how the user entered the date on the main form. I am trying to make it like a single entered date when the first text box is fill in and like a date range if an ending date is entered into the second text box. So if the ending date text box is blank, it should be ignored and the query should run as if filtering only on a specific date. I used the below expression and only entered the starting date, so it should only consider the field as being filtered by 1 date, not a range. But the query returns blank. [Text0] is the starting date and [Text3] is the ending date. The field is a job date field intended to only return job numbers from either that date or inside the date range.
Example: If [Text0] is set to 4/20/2015 and [Text3] is blank, the query should return job numbers A-18, B-18, and C-18. If [Text0] is set to 4/20/2015 and [Text3] is set to 4/27/2015, the query should return A-18, B-18, C-18, D-19, E-19, F-19. The difference between -18 and -19 is the week that it corresponds to.
=IIf((IsNull([Forms]![MainForm]![Text3])=True),[Forms]![MainForm]![Text0],Between [Forms]![MainForm]![Text0] And [Forms]![MainForm]![Text3])
I think what you need is something like this:
Select JobNumber, ...
from Jobs
where JobDate >= [Forms]![MainForm]![Text0]
and JobDate <= nz([Forms]![MainForm]![Text3],[Forms]![MainForm]![Text0])