本文介绍了不使用运算符之间获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为tblEvents的表,我需要从中选择当前日期和当前日期后一天之间的所有事件.我尝试了以下代码,但没有得到事件
I have got a table named tblEvents from which i need to select all the events between current date and one day behind the current date.I tried the following code but i am not getting events
select * from tblEvents where (CONVERT(varchar(24),tblEvents.dateEventDate,100)+'' ''+CONVERT(varchar(20),timeStartTime,100)) between (GETDATE()) and ((GETDATE()-1))
我该如何解决?
How can i solve this?
推荐答案
select * from tblEvents where (CONVERT(varchar(24),tblEvents.dateEventDate,100)+'' ''+CONVERT(varchar(20),timeStartTime,100)) between (GETDATE()) and (DATEADD(D,-1,GETDATE()))
您的代码无法正常工作,因为GetDate返回了DateTime值,这意味着如果您减去1,就不会减去1天!
Your code is not working, since GetDate returns a DateTime value, this means if you substract 1, you don''t substract 1 day!
select * from dbo.OFFLINE_TRANSACTIONS where dbo.FormatDateTime (CARDUPDATION_DATETIME) between
(getdate()-3) and (GETDATE())
如果在两次查询之间给相反,我什么也没有得到
if give reverse in the between query i am not getting any thing
between and (GETDATE()) and (getdate()-3)
第一个值应该比第二个要好.
First value shuld be grater than second one..
这篇关于不使用运算符之间获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!