Solved

Microsoft Access SQL Query

Posted on 2014-07-24
6
530 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
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.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

26 Experts available now in Live!

Get 1:1 Help Now