473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Queries and Date Fields

I constantly have problems with this and I am hoping someone can explain it to me. Does Access always output text into a query regardless of what the formating of the data is in the table?

I am generally needing to query by date and then confine the output to a specific date range. Once again I am having problems and I am wondering if it is because the field is no longer in date format after the query is performed. So when I include the "Between (11/1/2006) And (11/30/2006)" in the Criteria field it gives me no returns.

I am working with a very simple query. Here is a copy of the SQL language of the query:

SELECT Transactions.Date, Transactions.Card1, Transactions.TransTotal
FROM Transactions;

I would greatly appreciate any explanations and suggestions.
Thank you!
Jan 8 '07 #1
14 2181
ADezii
8,834 Expert 8TB
I constantly have problems with this and I am hoping someone can explain it to me. Does Access always output text into a query regardless of what the formating of the data is in the table?

I am generally needing to query by date and then confine the output to a specific date range. Once again I am having problems and I am wondering if it is because the field is no longer in date format after the query is performed. So when I include the "Between (11/1/2006) And (11/30/2006)" in the Criteria field it gives me no returns.

I am working with a very simple query. Here is a copy of the SQL language of the query:

SELECT Transactions.Date, Transactions.Card1, Transactions.TransTotal
FROM Transactions;

I would greatly appreciate any explanations and suggestions.
Thank you!
Specifying "Between (11/1/2006) And (11/30/2006)" as a Criteria tells the Query Engine to search for that specifc String and not a Date Range. The fact that you did not mention if you received a Data Type Mismatch Error tells me that your Date Field is defined as Text and not Date/Time. The Criteria for searching a date Field for a given range would be Between #11/1/2006# And #11/30/2006#. The underlying Field, however, must be defined as Date/Time in order to assure accurate results.
Jan 8 '07 #2
Thank you! That worked. So am I safe to take from this that performing a query does not change the format of the date field? (I am trying to increase my understanding of Access in general.)

Also, now that that is working I seem to have another problem. I want to group the data coming out of the query by date. I have set the first column to group and the second colum to sum and yet I am getting approx 10 entries all from 12/1/2006. Do I need to do something else to get them to goup?
Jan 8 '07 #3
NeoPa
32,556 Expert Mod 16PB
This may be helpful (Literal DateTimes and Their Delimiters (#).)
Jan 9 '07 #4
ADezii
8,834 Expert 8TB
Thank you! That worked. So am I safe to take from this that performing a query does not change the format of the date field? (I am trying to increase my understanding of Access in general.)

Also, now that that is working I seem to have another problem. I want to group the data coming out of the query by date. I have set the first column to group and the second colum to sum and yet I am getting approx 10 entries all from 12/1/2006. Do I need to do something else to get them to goup?
Be more specific on the Fields involved in the GROUP BY and SUM clauses
Jan 9 '07 #5
Please let me know if any more info would be helpful.

Here is my query displayed in SQL:
SELECT Transactions.Date, Sum(Transactions.TransTotal) AS SumOfTransTotal
FROM Transactions
GROUP BY Transactions.Date
ORDER BY Transactions.Date;

And here is a sample of the data returned:
Date SumOfTransTotal
12/13/2005 5.12
12/13/2005 5.12
12/13/2005 5.12
12/13/2005 5.12
12/15/2005 1.15
12/15/2005 1
12/15/2005 0.12
12/15/2005 6.56
12/16/2005 19.14
12/16/2005 12
12/16/2005 8.16
12/17/2005 11.11

Why will it not group all the 12/13 or 12/15's together? I have done other queries like this and not had this problem. What am I overlooking?

Thanks,
Jan 9 '07 #6
NeoPa
32,556 Expert Mod 16PB
If Transactions.Date is stored as a Date/Time field and has a time component which is simply not displayed, then that would explain this behaviour.
Jan 9 '07 #7
What do you recommend as a solution? Cdate? Format command? I am not experienced at all with this kind of problem. Thanks.

I just had another thought. Is there a way to put in wild cards for the time stamps so that it will still group by the day?
Jan 9 '07 #8
NeoPa
32,556 Expert Mod 16PB
In short No.
You will need to use :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Date],Sum([TransTotal]) AS SumOfTransTotal
  2. FROM Transactions
  3. GROUP BY Format([Date],'yyyymmdd')
  4. ORDER BY Format([Date],'yyyymmdd')
Jan 9 '07 #9
I attempted to translate your suggestion into my database with the following code:

SELECT Transactions.Date, Sum(Transactions.TransTotal) AS SumOfTransTotal
FROM Transactions
GROUP BY Transactions.Date, Format([Transactions.Date],'yyyymmdd')
ORDER BY Transactions.Date, Format([Transactions.Date],'yyyymmdd');

And the output is:

Date SumOfTransTotal
12/13/2005 5.12
12/13/2005 5.12
12/13/2005 5.12
12/13/2005 5.12
12/15/2005 1.15
12/15/2005 1
12/15/2005 0.12
12/15/2005 6.56
12/16/2005 19.14
12/16/2005 12
12/16/2005 8.16
12/17/2005 11.11
12/19/2005 9.68

It still has not grouped all the 12/13s. Are there other possible reasons for this besides a timestamp that is unseen in the date field?
Jan 9 '07 #10
NeoPa
32,556 Expert Mod 16PB
Yes.
The possible, in fact definite, reason it doesn't work is that you changed it not to. Of course your version didn't work. You included the Date field - hence GROUPing by the time element by definition.
Why do you come back here and ask for more help before even trying the version I suggested?
Jan 9 '07 #11
I am sorry if somehow I have messed up. Did I miss something? If I did it was innocent. I tried the code you suggested exactly as suggested and it returned the following error:

You tried to execute a query that does not include the specified expression 'Date' as part of an aggregate function.

I was trying to learn from what you wrote and thought that if I attempted to change the table names I might figure it out. I don't understand what I did that was wrong. The ability to ask questions in these networks is important to me. I will not do whatever I am not supposed to do.
Jan 9 '07 #12
NeoPa
32,556 Expert Mod 16PB
You're good Burton.
You confused me by leaving out the info you just posted. From your earlier post it seemed as if you'd just decided, without checking what I'd posted, to make your own changes.
Making your own changes after my code failed, is a good thing. Not telling me the sequence so that I could understand too, was where the confusion arose.
As I say - not a problem.
Your error message makes sense and indicates to me what I had overlooked.
A more reliable version should be (and I have used a different concept here in view of the problem found) :
Expand|Select|Wrap|Line Numbers
  1. SELECT CDate(Int(Transactions.Date)) AS [Date],
  2.        Sum([TransTotal]) AS SumOfTransTotal
  3. FROM Transactions
  4. GROUP BY CDate(Int(Transactions.Date))
  5. ORDER BY CDate(Int(Transactions.Date))
Jan 9 '07 #13
Wow. That seems to have worked. I am going to run some other steps and hopefully it will take. Thank you very much!

One other quick question. Without getting a book on SQL (which I plan to do) is there somewhere on this network or on the web that has a Cliff Notes version of when to use brackets and when to use parenthesis and other language formatting tips?

Thank you again!
Jan 9 '07 #14
NeoPa
32,556 Expert Mod 16PB
Not that I'm aware of I'm afraid.
You may find something if you follow through on some of the links in (Links to useful sites)

Oh, and btw, you may express surprise when my code fails - but when it works - that's just harsh ;)
Jan 9 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Todd D. Levy | last post by:
Normally, I have a date field in the query that a report is based on that requests the user to select a start date and an end date. I now have a situation where there are 2 date fields that the...
4
by: Stewart Allen | last post by:
I'm trying to filter a table that has 2 date fields, the first date will always have a value but the second will only occasionally has a value. Each date field also has a corresponding text field...
1
by: Riley DeWiley | last post by:
I have an UPDATE query that is always setting 0 records. When I cut and paste the SQL into Access and use it, it fails in the same way unless I coerce the date fields to be '=now()', in which case...
5
by: QBCM | last post by:
I am trying to create a report by selecting three date fields from one table with records between a start date and end date. I have tried to adapt one of Allen Browne's scripts as follows but it...
2
by: anony | last post by:
Maybe this feature is already out there. I guess you could write triggers to do some of this. Often when designing a database I add a start_date and end_date column to the table. The start_date...
8
by: Ragbrai | last post by:
Howdy All, I have a query that is used for filtering results to be used in a combo box. The query needs to test fields from both a table and then unbound text boxes on the form that also contains...
2
by: jennwilson | last post by:
I am trying to generate a report based on a query that will list any records where an individual has a date listed that matches the specified time for one or both of the date fields. The two fields...
6
by: Ledmark | last post by:
Hello - I am in a class for Access 2007 Database apllication design and we are covering types of Validation rules. We have a problem that I'm trying to solve but have no idea how to go about writing...
2
by: KMEscherich | last post by:
Microsoft Access 2003 Hi there, am stuck with something that I am not sure on how to get done. I am attempting to have 3 check boxes and have 3 date fields. I need to have each date field be...
3
by: Miranda Truehill | last post by:
I'm very new to programming and although I've seen a similar post that addressed this in part, I am unsure how exactly to go about this. I know I can utilize the DateAdd function but don't know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.