我有一个包含如下表的数据库:-
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 作为日期调用数据时获取额外数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合