sql period cross-check whether there is an intersection

- 11 bis end of the event time period greater than the current time represents the server activity 
- achieved. 1 
SELECT   *   from   ProdCar A   WHERE    A.EndDate >  GETDATE ()
 and   A.EndDate > = ' 2019-11-07 00: 00: 00.000 '  
the aND  ' 2019-11-07 18 is: 00: 00.000 '  > A.BeginDate
 - implement 2 
- given time interval (begin, end), the database fields BeginDate EndDate, now determines whether there is an intersection between them 
the SELECT  *  the FROM ProdCar A    WHERE    A.EndDate >  GETDATE ()
 the AND   the NOT   ((A.EndDate < '2019-11-04 00:00:00.000') OR (A.BeginDate > '2019-11-05 18:00:00.000'))
--实现3
select * from ProdCar  A
where A.EndDate> GETDATE() AND 
(A.BeginDate > '2019-11-04 00:00:00.000' AND A.BeginDate <'2019-11-05 18:00:00.000')   OR (A.BeginDate < '2019-11-04 00:00:00.000' AND A.EndDate >'2019-11-05 18:00:00.000')
    OR(A.EndDate > '2019-11-04 00:00:00.000' AND A.EndDate <'2019-11-05 18:00:00.000')
--实现4
SELECT * FROM ProdCar A   where   A.EndDate> GETDATE()
and
( A.BeginDate between '2019-11-04 00:00:00.000' and  ('2019-11-05 18:00:00.000') )          
OR ( A.EndDate  between  '2019-11-04 00:00:00.000' and ('2019-11-05 18:00:00.000') )    
OR ( '2019-11-04 00:00:00.000' between A.BeginDate AND A.EndDate )                  
OR ( '2019-11-05 18:00:00.000' between A.BeginDate AND A.EndDate ) 

 

Guess you like

Origin www.cnblogs.com/Warmsunshine/p/11799711.html