我希望check date
中between two dates
或NULL
传递declare @fromDate date = null
declare @toDate date = null
select * from Mytable
where date betweeen @fromDate and @toDate OR NULL (how to check for both parameters)
使用存储过程
码
{{1}}
我还有其他2个参数,所以不论日期结果如何都应该显示。 如果@todate和@fromDate为NULL
请帮忙。
答案 0 :(得分:10)
尝试使用合并功能,如下所示
declare @fromDate date = null
declare @toDate date = null
select * from Mytable
where date between coalesce(@fromDate,date) and coalesce(@toDate,date)
答案 1 :(得分:1)
几乎将您的英语转换为SQL:
where (date is null or date betweeen @fromDate and @toDate)