SQL中的日期范围查询 [英] date range query in sql

查看:93
本文介绍了SQL中的日期范围查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个包含startdate和enddate列的表.

前开始日期结束日期
2011-07-13 00:00:00.000 2011-07-14 00:00:00.000


我想在开始日期的基础上进行搜索
问题是,如果我输入开始日期为2011-07-13 00:00: 01 .000


hi all,


i have a table which contains startdate and enddate column.

ex startdate enddate
2011-07-13 00:00:00.000 2011-07-14 00:00:00.000


i want to perform a search on the basis of startdate
the issue is that if i enter strat date as 2011-07-13 00:00:01.000


the above record should be displayed.

推荐答案

@givenTime =``2011-07-13 00:00:01.000''

select * from [table] where startdate < @givenTime and enddate > @givenTime
@givenTime = ''2011-07-13 00:00:01.000''

select * from [table] where startdate < @givenTime and enddate > @givenTime


尝试从此处进行的操作 [ ^ ]-可能会有所帮助.
Try something from here[^] - it may help.


没有那么困难

Not that difficult

SELECT *
FROM table
WHERE @date >= startdate AND @date <= enddate


这篇关于SQL中的日期范围查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆