I have a table that has more than one date fields (say six or seven) and I just want to retrieve only the dates that match today's date. Please help. Really appreciate it thanks
This is a very specific problem, so the best way to get the result you want is to code some part as an script on access.
For getting those rows where at least one date is the same as today's date, you should use something like this.
SELECT * FROM Table t
WHERE Date() IN (t.field1, t.field2, ...)
You should add all the fields you want to check inside IN clause.
On the Access for you should be able to process the data.
Related
Here's a simplification of my data. I have these events occurring by date. The "x" marks the day each event occurred.
What I'm doing is counting how many events happened in each month, using COUNTIF(). So I have something like:
The problem is: I use one COUNTIF() for each month and it can be very tricky when you have, let's say, 50 months.
How can I resolve this with VBA? If wasn't separated by date would be easy, but I haven't able to solve this.
I appreciate it if someone can help.
Just use a Pivot Table to group by month-end and count the records.
https://trumpexcel.com/group-dates-in-pivot-tables-excel/
https://www.myexcelonline.com/blog/group-month-excel-pivot-tables/
If you need to do this frequently, you can record a Macro, save it, and run it whenever you need it.
I need a flexible table that displays dates. By flexible, I mean, if I put in June 15, 1976, it displays as such. But if I put 20, Access calculates that 20 in the same field as today's date - 20 years.
I set the formatting of the date/time field in table: tbl_ageLimit to #, so it displays a serial date rather than a user readable date. This table has one field: ageLimit.
I am trying to develop a query to recognize if the date is not relevant in its current state and then convert it to something relevant and put it in another table that will constantly update.
Right now, I'm just trying to get formula to work on recognizing and converting the date. This is the formula that works splendidly in excel, but doesn't seem to be working in MS Access:
IIF([ageLimit]<=100,Date()-365*[ageLimit],[ageLimit])
It recognizes if the field has a number in it that is less than 100. But it's not doing the math and displaying a new record in the new table. Below is the sql:
SELECT tbl_ageLimit.ageLimit INTO tbl_allAges
FROM tbl_ageLimit
WHERE (((tbl_ageLimit.ageLimit)=IIf([ageLimit]<=100,Date()-365*[ageLimit],[ageLimit])));
Can someone kindly point out to me what I'm doing wrong? Thank you.
As requested, here are snapshots of the problem:
The table that is created is not showing the fifth record. Stumped.
Consider removing the WHERE clause as you do not need to filter records. Since you intend to evaluate the IIF() expression, place in the SELECT clause:
SELECT IIf([ageLimit]<=100, Date()-365*[ageLimit], [ageLimit]) As [age_Limit]
INTO tbl_allAges
FROM tbl_ageLimit
I have a table with many entrys but i only want to display the items with quantity over 0. What a query like that would be like? and how do i use it? Complete noob in Access and VBA
Going by just what you said, you can try the following query:
SELECT *
FROM yourTable
WHERE quantity > 0
You need to use a combination of VBA and SQL. I assume you wish to use vba, as you added the tag. A good place to start is here:
http://www.fontstuff.com/access/acctut15.htm
That said if you just want to use the SQL query then Tim's answer has everything you need
I need to add every day to some query result a column A for sysdate, and next day as well, and next day as well, etc.
So you will have the same select which will always add for new day a new column for actual date.
Is this somehow possible in sql without using INSERT, UPDATE and other rewriting statements?
Thank you very much for your answers :)
Im using a Oracle SQL Developer
SQL queries give you a fixed number of columns and a variable number of rows. If every day means more data to you then you would have a query to result in more rows usually. It's up to a GUI to display retrieved data in the most convenient way (one column per day in your example).
So, yes and no. Yes, you can (very easily) write a query to give you more data each day. No, you cannot write a query that results in a new column every day. But as mentioned, this is not what SQL is made for anyhow. SQL is the data retrieving language. You use a programming language or a report tool to display the data to your users.
In my Access database, I have a table called customers. In this table I have a column called DateEntered. The data type for the field is short text.
The values in this column are not coherent - they come in several variations:
MM-DD-YYYY,
MMDDYYYY and
MM/DD/YYYY.
There doesn't seem to be any standard set.
My goal is to select all customers from 2012. I tried
select *
from customers
where DateEntered <('%2013') AND >('%2012');
but it comes up blank when I run it.
Can anyone point out what I'm failing to do correctly & more importantly explain why exactly this query doesn't work in Access? From my understanding of SQL (not very advanced) this should work.
Another variant)
select * from customers where RIGHT(DateEntered, 4) = '2012'
If you have control over the database and application code, the best way to handle this is to use an actual Date field instead of text in the table.
One way to handle this would be to add a new field to the table, write a query or two to correctly convert the text values to actual date values, and populate the new field.
At this point, you would then need to hunt down the application code the refers to this field in any way and adjust to treat the field as a date, not text. This includes your insert and update statements, report code, etc.
Finally, as a last step, I would rename the original text field (or remove it altogether) and rename the new date field to the original field name.
Once you fix the problem, querying against the field will be a piece of cake.
Alternatively, if you can't alter the table and source code, you can use the date conversion function CDATE() to convert the text value to an actual date. Note that you may need to guard against non-date entries (NULL or empty string values, as well as other text values that aren't really dates in the first place). The IsDate() function can be your friend here.
If you have the time and patience, fixing the data and code is the better approach to take, but sometimes this isn't always feasible.
Why don't you use LIKE operators (they're appropriate when you have a pattern using % and _):
select * from customers where DateEntered like '%2013' or DateEntered like '%2012'