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])
Related
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'm stuck at this point, I get my data from a stored procedure with the date format as MM/YY, but SSRS sorted my date in a wrong way: 01/2019, 02/2019,..., 12/2019;01/2018, 02/2018,...
So I'd like to do to have my data in the right order.
Since your date is converted to MM/YYYY format, the data is text and not numerical so it's sorted one character at a time rather than by the value.
If you want to sort by year and then by month, you would need a separate SORT option for each that parses the text into separate month and year values.
=RIGHT(Fields!DOB.Value, 4)
This gets the 4 characters from the right of the text which is the year in the data.
=LEFT(Fields!DOB.Value, 2)
LEFT , 2 gets the first two characters of the string - the month in the field.
Create a new column in the query where you convert the string date to a date data-type and sort on that e.g.
select
convert(date, '01/'+ MyDateStringColumn) MyDateColumn
from MyTable
order by MyDateColumn
How to write the query in mysql where i pass a date variable, it can list down all the date within that week.
etc. if i pass date = 6-12-2016,
the query will print:
date
4-12-2016
5-12-2016
6-12-2016
7-12-2016
8-12-2016
9-12-2016
10-12-2016
You need to generate a Calendar Table like on this SO question:
How to populate a table with a range of dates?
And then run the following query:
SELECT *
FROM calendar_table
WHERE WEEK(date_column, 0) = WEEK('2016-12-06', 0);
This will produce output you want. 0 number in the argument describe mode in WEEK function. You can change the number to another number according to your needs. See MySQL Documentation about WEEK function.
I have a query in Access where I want to select a range of dates from a calculated field in the query.
The field is populated using the following expression:
DueDate: DateAdd("m",-([PMI job lookup table]![Frequency]),[Date])
I'd like to select everything from a certain month and year from this field.
For example I'd like to list all the jobs in say May 2014.
In your query, add this criteria for the field of DueDate:
Between DateSerial(2014,5,1) And DateSerial(2014,5+1,0)
This will filter for dates between 2014-05-01 and 2014-05-31.
If I have MySQL query like this, summing word frequencies per week:
SELECT
SUM(`city`),
SUM(`officers`),
SUM(`uk`),
SUM(`wednesday`),
DATE_FORMAT(`dateTime`, '%d/%m/%Y')
FROM myTable
WHERE dateTime BETWEEN '2011-09-28 18:00:00' AND '2011-10-29 18:59:00'
GROUP BY WEEK(dateTime)
The results given by MySQL take the first value of column dateTime, in this case 28/09/2011 which happens to be a Saturday.
Is it possible to adjust the query in MySQL to show the date upon which the week commences, even if there is no data available, so that for the above, 2011-09-28 would be replaced with 2011/09/26 instead? That is, the date of the start of the week, being a Monday. Or would it be better to adjust the dates programmatically after the query has run?
The dateTime column is in format 2011/10/02 12:05:00
It is possible to do it in SQL but it would be better to do it in your program code as it would be more efficient and easier. Also, while MySQL accepts your query, it doesn't quite make sense - you have DATE_FORMAT(dateTime, '%d/%m/%Y') in select's field list while you group by WEEK(dateTime). This means that the DB engine has to select random date from current group (week) for each row. Ie consider you have records for 27.09.2011, 28.09.2011 and 29.09.2011 - they all fall onto same week, so in the final resultset only one row is generated for those three records. Now which date out of those three should be picked for the DATE_FORMAT() call? Answer would be somewhat simpler if there is ORDER BY in the query but it still doesn't quite make sense to use fields/expressions in the field list which aren't in GROUP BY or which aren't aggregates. You should really return the week number in the select list (instead of DATE_FORMAT call) and then in your code calculate the start and end dates from it.