Solved

Microsoft Access SQL Query

Posted on 2014-07-24
6
531 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 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 35

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

770 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