[英]SQL between in case in where clause
我嘗試編寫一個查詢,該查詢返回的數據在參數不為null的情況下,參數結果與參數-12個月之間的Date_column,或者在param為null的情況下,Date_column不為null。 你能幫助我嗎? 我嘗試了許多變體,但始終會出現一些錯誤。
declare @my_date DateTime
select * from MyTable
where
case when @my_date is null
then Date_column is not null
else Date_column between @my_date and DATEADD(MONTH, -12, @my_date)
end
你寫你的條件,如下所示,不帶case
表達式
where (Date_column is not null and @my_date is null ) or
(Date_column between DATEADD(MONTH, -12, @my_date) and @my_date)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.