Sql Query不显示所选日期的数据 [英] Sql Query not showing data for selected date

查看:81
本文介绍了Sql Query不显示所选日期的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!



我在DB中有日期时间字段,存储发票日期(格式为2014年7月15日上午12:00:00)


然后我有两个datetimepickers,用于From date和To。



我试图通过SQL获取它查询

Hello!

I have datetime field in DB, which stores invoice dates (format is 7/15/2014 12:00:00 AM)

Then I have two datetimepickers, for From date and To date.

I am trying to get it through SQL query

Where TRDate between @DT1 and @DT2 Order By TRRef DESC 





问题是,如果我使用日期时间选择器选择7/15/2014,它不会显示第15个数据。为此,我需要选择第14位。



未选择包含日期?



谢谢



The problem is, If I select 7/15/2014 using datetime picker, it does not show the data for 15th. For this I need to select 14th.

Isn't selected date inclusive?

Thanks

推荐答案

如果您查看BETWEEN的W3Schools信息: http:/ /www.w3schools.com/sql/sql_between.asp [ ^ ]

您将在底部看到:



请注意,BETWEEN运算符可以产生不同的结果在不同的数据库中!

在某些数据库中,BETWEEN选择介于测试值之间和排除测试值的字段。

在其他数据库中,BETWEEN选择介于测试之间的字段值。

在其他数据库中,BETWEEN选择测试值之间的字段,包括第一个测试值和不包括最后一个测试值。



因此:检查数据库如何处理BETWE EN运营商!




由于我们不知道您使用的是哪个数据库,我们甚至无法发表评论!
If you look at the W3Schools info for BETWEEN: http://www.w3schools.com/sql/sql_between.asp[^]
You will see at the bottom:

"Notice that the BETWEEN operator can produce different result in different databases!
In some databases, BETWEEN selects fields that are between and excluding the test values.
In other databases, BETWEEN selects fields that are between and including the test values.
And in other databases, BETWEEN selects fields between the test values, including the first test value and excluding the last test value.

Therefore: Check how your database treats the BETWEEN operator!"


Since we don't know which DB you are using, we can't even begin to comment!


Where TRDate between @DT1 and DATEADD(DD,1,@DT2) Order By TRRef DESC 



试试这个


Try this


这篇关于Sql Query不显示所选日期的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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