Solved

Access, SQL: how to select dates older than

Posted on 2009-07-06
8
277 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
  • 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
 
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
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!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

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

22 Experts available now in Live!

Get 1:1 Help Now