![](/img/trans.png)
[英]How do I query for all dates greater than a certain date in SQL Server?
[英]How do I create a query with greater than one date and not between some other dates?
所以我需要撤回 2017 年 1 月 1 日之后但不是 2016 年 10 月和 2016 年 12 月 31 日之間的數據
這是我當前的代碼:
SELECT [SequenceID]
,[AppointmentDate]
FROM dbo].[AmsAppointment]
where AppointmentDate >= Convert(datetime, '2017-01-01' ) and AppointmentDate <= Convert(datetime, '2016-10-01' )
我知道代碼是錯誤的,所以請幫助我。
您可以通過多種方式執行此操作,但我認為not between
最好not between
:
SELECT [SequenceID], [AppointmentDate]
FROM [dbo].[AmsAppointment]
where
AppointmentDate >= '2017-01-01' and
AppointmentDate not between '2016-10-01' and '2017-12-31'
也許你的例子就是這樣,但在你的場景中,由於范圍重疊,這真的轉化為:
AppointmentDate >= '2017-12-31'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.