?
Solved

Microsoft Access SQL Query

Posted on 2014-07-24
6
Medium Priority
?
537 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 38

Accepted Solution

by:
PatHartman earned 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

764 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