--雙11活動結束時間大於當前服務器時間表明有效期的活動 --實現1
select * from ProdCar A where A.EndDate> GETDATE() and A.EndDate >='2019-11-07 00:00:00.000'
AND '2019-11-07 18:00:00.000' > A.BeginDate --實現2 --給定時間區間(begin,end),數據庫字段BeginDate與EndDate,如今要判斷它們之間是否有交集
SELECT * FROM ProdCar A where A.EndDate> GETDATE() AND 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 )