【发布时间】:2017-04-25 16:15:32
【问题描述】:
从两列检索两个日期之间的数据的 SQL 查询
select distinct mname
from tb_reqmach
where fromdate >= '2016/12/08'
and todate <= '2016/12/30'
and mcfact = 'BSC - 3'
group by mname
当我使用上述查询时,它返回 null。来自 db 的值
The figure attached is the data saved in db
当起始日期和两个日期在保存日期之间时,请帮助检索行
当我使用时
select distinct mname
from tb_reqmach
where fromdate >= '2016/12/01'
and todate <= '2016/12/30'
and mcfact = 'BSC - 3'
group by mname
它检索行,当我使用时
select distinct mname, fromdate
from tb_reqmach
where '2016/12/08' between fromdate and todate
这也检索行
但我需要按我的要求检索
【问题讨论】:
-
您的要求有点不清楚。在您的第一个查询中,您提到了 fromdate>= '2016/12/08' 和 todate
-
用当前输出和异常输出定义表
-
比较日期可以使用datediff函数:datediif(d,'2016/12/08', fromdate)>=0 and datediif(d, todate,,'2016/12/30')> =0 。实际上,我认为检查日期范围,每个日期列点需要两个日期
-
如果fromdate是2016-12-01并且todate是201-12-30保存在db中
-
如果我选择 2016-12-08 到 2016-12-25 之间的数据,它必须检索保存为 2016-12-01 作为起始日期和 2016-12-30 作为今天的数据
标签: c# sql asp.net sql-server sql-server-2008