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.
Related
I have a table named as energymeter which have 3 columns named as Date, Name, Value.
I want a result of highest value of day- minimum value of day of each day in specified time period of individual parameter (Name) into 3 separate columns.
Here is my table structure
And i am getting result for single parameter as i wish using query
select Date(Date) as Date,
Max(Value) - Min(Value) as Value ,
Name
from energy_meter.energy_meter
WHERE Name ='Energy_Meters\[1\].Total_active_energy_kWh'
And DATE(Date) between '2022-10-01' and '2022-10-13'
group by DATE(Date)
and getting result as below
and i want result should look like below for all 3 parameters
Community help is needed.
Thanks
I am using MS Access for FX rate data. I have a table which lists currencies and their associated FX rate. Each column has the rate for a different month. e.g. "January 2019", "February 2019" etc
I have another table which has a list of dates and currencies, and I want to create a select query which returns the FX rate for the relevant currency for the relevant month.
I have created a field which converts the date to the format which matches the field name in the source data table, so for example the date 12/01/2019 is shown as January 2019 (and defined this as FX_period)
Basically, I want the source field used to be based on another field in that query.
For example:
January dates: source field is TBL10_FX_BS_Rates.[January 2019] AS FX_Rate
February dates: source field is TBL10_FX_BS_Rates.[February 2019] AS FX_Rate
So in the end I just have 3 columns: Date, Currency and FX rate
I have tried lots of things, including:
SET "[tablename]!["&FX_period&]" as FX_RATE
Hope this makes sense!
A table with a field for each mon/yr is not a normalized structure. Normalize TBL10_FX_BS_Rates structure then join tables in query. Actually, normalized table might be enough - depends if there are other fields in currencies table. Otherwise, use DLookup() - something like:
SELECT CurrencyDate, Currency,
DLookUp(Format([CurrencyDate],"mmmmyyyy"),"TBL10_FX_BS_Rates","Currency='" & [Currency] & "'") AS Rate
FROM Currencies;
Advise not to use spaces nor punctuation/special characters (underscore only exception) in naming convention.
I have information to be collected monthly. same data columns but different content of course. I'm asking about which are the best way to make the user insert this data, should I make a database table for each month with the same columns, or should I make one table with one column to determine the month.
For example:
table: July
id|program_name|program_date|program_result
table: June
id|program_name|program_date|program_result
Or:
table: monthly_info
id|program_name|program_date|program_result|month
I'm asking which way is more efficient than the other.
Thank you
Create one table to save all your data with date.
table: monthly_info
id|program_name|program_date|program_result|date
Then you can query monthly data as below.
If your condition month parameter is integer. Use this query. (this will return all data matches to month August)
SELECT * FROM monthly_info WHERE MONTH(date) = 8
If your condition month parameter is string. Use this query.
SELECT * FROM monthly_info WHERE DATENAME(mm, date) = 'August'
first off: I know virtually nothing about MS Access but now I'm in a situation where I have to use it (dataset is too big for Excel). The data has column names like Customer_Name, Product Name, Amount, Date
Date refers to the last day of a month, so for example for February it's 28/02/2013. Now I want to compare the amount a customer bought in February to the amount he/she bought in January and calculate the difference. So far, I've been able to this by prompting the user to enter the date.
SELECT Data.Customer_Name,
Sum(IIf(Format(Date,"yymm")=[Startdate (yymm)?],Amount,0)) AS Amount_Startdate,
Sum(IIf(Format(Date,"yymm")=[Enddate (yymm)?],Amount,0)) AS Amount_Enddate,
Amount_Enddate-Amount_Startdate AS Difference
FROM Data
GROUP BY Data.Customer_Name;
This works but is it possible for Access to recognize which dates are in the column "Date" (there are only two distinct dates) so the user does not have to enter anything? Also, I tried to replace "Amount_Startdate" with a field that has the respective date in its name (e.g. "Amount_Feb2013") and played around with ampersand but it didn't work.
If you create a new table called tblValues with just 2 fields; ID and TDate (always try to avoid using reserved words like "Date", "System" or other words that Access already assigns a function to), you can fill it like this:
ID TDate
-- ---------
ST 1/31/2014
EN 2/28/2014
Then you could use the DLookup function to make this code generic:
SELECT Data.Customer_Name,
Sum(IIf(Format(Date,"yymm")=DLookup(Format(TDate, "yymm"), tblValues, "ID = 'ST'"),Amount,0)) AS Amount_Startdate,
Sum(IIf(Format(Date,"yymm")=DLookup(Format(TDate, "yymm"), tblValues, "ID = 'EN'"),Amount,0)) AS Amount_Enddate,
Amount_Enddate-Amount_Startdate AS Difference
FROM Data
GROUP BY Data.Customer_Name;
Then you could just update the table with the values you want to use as start and end dates whenever you want.
I would like to include the name of the day in my query in ms access?
I know how to do it from the query designer in the format field as 'dddd', but want to rather add it in the sql editor as part of my statement.
Its part of a select, from, where, group by, order by statement where the date is specified in the where clause but i want it to display as the name of the day ie Tuesday in another column.
Thanks
Format works for queries, too:
SELECT ADate, Format([ADate],"dddd") AS ADay
FROM Table1;
Here is a select statement that returns you the day name from the date time
SELECT datename(dw,GETDATE()) AS 'Day Name'
This gives me the current day name.