Solved

Microsoft Access SQL Query

Posted on 2014-07-24
6
527 Views
Last Modified: 2014-07-24
Can I write an SQL query in MS Access 2002?

Specifically, "SELECT * from Workorder where DateEntered > 3/1/2014".

I am accustomed to using MySQL where the date is stored yyyy-mm-dd; not sure if the Access date format is correct as I stated it.

If I can do this, how do I build it (in Access) & Run it? Can I store the "result set" as a table?

Thanks
0
Comment
Question by:Richard Korts
  • 3
  • 2
6 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40217548
if [DateEntered] is DateTime field you need to enclose the date value in #

"SELECT * from Workorder where DateEntered > #3/1/2014#"
0
 

Author Comment

by:Richard Korts
ID: 40217580
OK, but I'm not familiar with how / where to compose the query, etc.

I used Access, YEARS ago.

Thanks
0
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40217620
Dates in Access and most other RDBMS' are not stored as strings.  They are stored as double precision numbers where the integer portion represents the number of days since a particular date which is referred to as the origin date.  The decimal portion represents the time since midnight.

print cdbl(now())
 41844.5865393519
print now()
7/24/2014 2:04:41 PM
So for the above example, there have been 41844 days since Dec 30, 1899 which is what Access uses as the origin date.   Other RDBMS' and also Excel and Word use the same concept but different origin dates.  

To create a query against a linked table in Access, the simplest method is to just open the query designer.  The opening dialog lets you choose tables and/or queries.  Once they are selected, close the dialog.  Then draw join lines between all the tables/queries you selected.  Next, choose the columns you want from each table/query.  And the final step is to add any criteria if necessary.  So, in your case, you would put:

> #3/1/2014#

in the criteria cell beneath the DateEntered field.

The format of a date is ONLY relevant to people.  Access defaults to the windows default date format which in the US is normally "mm/dd/yyyy".  In other countries it could be "dd/mm/yyyy".  In either case, the data is stored internally the same way as a double precision number.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Richard Korts
ID: 40217688
I can't just write a simple SQL Query in Access?
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 40217713
That IS how you create a query in Access.  If you prefer, you can switch to SQL view and type it yourself.  If you are talking about running a query in code, you can write whatever SQL string you want or run a saved querydef.  Keep in mind that saved querydefs are more efficient than embedded SQL since the first time the querydef runs, Access calculates an execution plan and saves it.  Access then reuses the execution plan each time you run the query.  If the SQL is embedded in code, there is no way for Access to save an execution plan so each time you run the query, Access has to recalculate the execution plan.

I suggested the querydef (QBE) as the path of least resistance.  If you are not familiar with Access, you are unlikely to be familiar with its version of SQL syntax.  Using a visual interface eliminates the typing and syntax errors.
0
 

Author Closing Comment

by:Richard Korts
ID: 40217818
OK, it was pretty easy with the Query Builder.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now