使用 BETWEEN 作为日期调用数据时获取额外数据 [英] Getting extra data while calling data using BETWEEN for date

查看:33
本文介绍了使用 BETWEEN 作为日期调用数据时获取额外数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含如下表的数据库:-

I have a database with a table like:-

ID  Name Amount Date

001 abc 200 01/05/2014

001 abc 200 02/05/2014

001 abc 200 03/05/2014
.
.
.
001 abc 200 31/05/2014

001 abc 200 01/06/2014

001 abc 200 02/06/2014

执行以下查询时:

SELECT *
FROM table_name
WHERE Date_ between '01/05/2014' AND '31/05/2014'
ORDER BY CONVERT(DateTime, Date_, 103) DESC";

它显示了考虑日期 01/06/2014 和 02/06/2014 的额外数据,以及日期在 01/05/2014 和 31/05/2014 之间的数据

it is showing an extra data considering the dates 01/06/2014 and 02/06/2014, along with data of date between 01/05/2014 and 31/05/2014

如何解决?

推荐答案

你的中间不行,你需要使用-

your between will not work, you will need to use -

条件为

CONVERT(DateTime, Date_, 103) >= CONVERT(DateTime, '01/05/2014', 103) 和 CONVERT(DateTime, Date_, 103) <= CONVERT(DateTime, '31/05/2014', 103)

在您的 where 条件下.范围条件不能用于过滤日期之间的记录.

in your where condition. Range condition will not serve your purpose of filtering the records between dates.

这篇关于使用 BETWEEN 作为日期调用数据时获取额外数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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