0

The Employee table has four fields EmpNo,EmpName,FromDate and ToDate filelds. I have to select the EmpNo and EmpName where today’s date is between the from date and the to date.

Select EmpNo,EmpName from Employee where FromDate = Trunc(SYSDATE) And ToDate =Trunc(SYSDATE)

Is that the way of doing

xyz
  • 531
  • 1
  • 10
  • 31
  • 1
    Which DBMS do you use? – Jens Mar 18 '15 at 14:38
  • possible duplicate of [Check if current date is between two dates Oracle SQL](http://stackoverflow.com/questions/23398632/check-if-current-date-is-between-two-dates-oracle-sql) – Seymour Mar 18 '15 at 14:40
  • it is SQL database not Oracle – xyz Mar 18 '15 at 15:19
  • Oracle **is** using SQL. So your last comment doesn't make sense. If you are not using Oracle, then you *have* to tell us which DBMS you are actually using? ("SQL" is **not** a DBMS product, it's a query language used by all relational databases) –  Mar 18 '15 at 15:22

2 Answers2

0

Try

Select EmpNo,EmpName from Employee where Trunc(SYSDATE) between FromDate And ToDate 
Jens
  • 67,715
  • 15
  • 98
  • 113
0

No it's not. What you're testing now is if FromDate = ToDate = Trunc(SYSDATE), that is if Trunc(SYSDATE) equals both the other dates.

If you want to test if it's within a discrete range then this is what you want :

where Trunc(SYSDATE) >= FromDate and Trunc(SYSDATE) <= ToDate

or: where Trunc(SYSDATE) between FromDate and ToDate

Note that trunc(SYSDATE) suggests that you are using the Oracle database, but if you're using MS SQL you can use CAST(GETDATE() AS DATE) to get the date part of the current date.

jpw
  • 44,361
  • 6
  • 66
  • 86