1

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.

3
  • That's a lot of reading. have you considered something more general for SQL first?
    – gbn
    Commented Mar 26, 2012 at 14:13
  • The correct notation for an ANSI date literal is DATE '1970-01-01'. Note the single quotes around the actual date.
    – user1822
    Commented Mar 26, 2012 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
    Commented Mar 26, 2012 at 14:20

1 Answer 1

1

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'
2
  • Oracle would accept either of these as well assuming the proper NLS_DATE_FORMAT. Commented Mar 26, 2012 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
    Commented Mar 26, 2012 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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