Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Is it possible to do this in a SQL database

 SELECT * FROM Employee
    WHERE BirthDate BETWEEN DATE 1970-01-01 AND DATE 1970-01-01

The result that was said to from this query is all the employees that are born on 1970-01-01. This query has been taken from the following book Sorry if this question is lacking.

share|improve this question
    
That's a lot of reading. have you considered something more general for SQL first? –  gbn Mar 26 '12 at 14:13
    
The correct notation for an ANSI date literal is DATE '1970-01-01'. Note the single quotes around the actual date. –  a_horse_with_no_name Mar 26 '12 at 14:14
    
yeah I know it's a lot of reading but I am just skipping through most of it because most of it isn't really interesting on the research I am doing. –  mariomario Mar 26 '12 at 14:20

1 Answer 1

up vote 1 down vote accepted

Some variety of this, depending on RDBMS. SQL Server and MySQL accept date literals like this:

SELECT * FROM Employee
    WHERE BirthDate BETWEEN '1970-01-01' AND '1970-01-01'

SELECT * FROM Employee
    WHERE BirthDate BETWEEN '19700101' AND '19700101'
share|improve this answer
    
Oracle would accept either of these as well assuming the proper NLS_DATE_FORMAT. –  Leigh Riffel Mar 26 '12 at 15:29
    
Actaully this would only get the people born at midnight unless you are using SQL Server's date data type and not datetime. If you have times associated, you would want date>='1970-01-01' AND date<'1970-01-02' –  HLGEM Mar 26 '12 at 17:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.