Ruben rj Ruben rj - 4 months ago 14
SQL Question

how to compare multiple dates in where clause in sql

select truckid
from truck_log
where '20160804' between ruck_log.pickupdate and truck_log.ETA
and '20160806' between truck_log.pickupdate and truck_log.ETA


How to compare two dates inside where clause when I did this the query is accepting only the first comparison?

Answer

Add "OR" instead of "AND" in where clause :

Query :

select truckid from truck_log 

where  ('20160804' between truck_log.pickupdate and truck_log.ETA) 

      or ('20160806' between truck_log.pickupdate and truck_log.ETA)
Comments