Solved

Access, SQL: how to select dates older than

Posted on 2009-07-06
8
335 Views
Last Modified: 2012-05-07
Hi X-perts,

I need to select records with the date field older than a certain date;

"SELECT [MSCI] FROM EFdb WHERE [dates] >= 9/1/2006"

It returns ALL the records and doesn't filter the dates

What is the correct syntax for this?

Thanks
0
Comment
Question by:andy7789
[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
  • 2
  • +1
8 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24791044
Try quoting the date. 9/1/2006 will probably be evaluated as a fractional number instead of a date.
0
 
LVL 11

Accepted Solution

by:
datAdrenaline earned 500 total points
ID: 24791093
Quotes are not the literal date delimiter ... you should use the octothorpes (#) ...

"SELECT [MSCI] FROM EFdb WHERE [dates] >= #9/1/2006#"

A note about the octothorpes delimiters, it will force Jet/Access to assume US date format if the date is in an ambiguous format, so, when creating my SQL statements via code, I will use an unabiguous formation ....

"SELECT [MSCI] FROM EFdb WHERE [dates] >= #2006-09-01#"
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24791149
This is how you do it in T-SQL:
"SELECT [MSCI] FROM EFdb WHERE [dates] >= '20060901"

Or more appropriately (assuming US mdy format):
"SELECT [MSCI] FROM EFdb WHERE [dates] >= CONVERT(datetime, '9/1/2006', 101)"
0
Independent Software Vendors: 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!

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24791153
P.S. If this is not an MS SQL Server question, please refrain from adding the MS SQL Server Zone.
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 24791182
Good follow up acperkins ... in T-SQL the date delimiter is the single quote .... so ... I persoally still stick with International format ...

SELECT [MSCI] FROM EFdb WHERE [dates] >= '2006-09-06'
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24791352
>>Quotes are not the literal date delimiter ... you should use the octothorpes (#) ...

Since the question was in the SQL Server Zone I assumed it was a SQL Server query. I did not notice Access in the zones when I answered.
0
 

Author Comment

by:andy7789
ID: 24791398
Thank you all! Sorry for the confusion with the zones  :)
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 24791443
>> Since the question was in the SQL Server Zone I assumed it was a SQL Server query <<

LOL ... I looked at the title and saw "Access" ... I didn't even see the Zone! ... :-S
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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
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…

636 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