SQL SERVER中,日期比较的问题,求各位帮忙,在线等待!(30分)

  • 主题发起人 主题发起人 qutwah
  • 开始时间 开始时间
Q

qutwah

Unregistered / Unconfirmed
GUEST, unregistred user!
有一表记录如下:<br>Autoid &nbsp; &nbsp; Employeeid &nbsp; &nbsp; &nbsp; Kqtime<br>1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2008-02-16 08:01:00<br>2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2008-02-17 1:05:00<br>3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2008-02-17 08:01:00 <br>我想查询所有记录KqTime值在当天23:30:00至第二天01:30:00的记录,我写了下面语句,但查询不到结果,请问各位,该如何修改下面语句实现我想要的需求呢?<br>Select * from KqRecord Where (Employeeid=1) And <br>(Cast(KqTime As DateTime) Between CAST(Convert(Varchar(10),KqTime,120)+Space(1)+'23:30:00' AS DATETIME) And <br>CAST(Convert(Varchar(10),KqTime,120)+Space(1)+'01:30:00' AS DATETIME))
 
试试:我没测试<br>Select * from KqRecord Where (Employeeid=1) And <br>Cast(KqTime As DateTime) &gt;= Convert(Varchar(10),KqTime,120)+Space(1)+'23:30:00' And Cast(KqTime As DateTime) &lt;= Convert(Convert(Varchar(10),KqTime+1,120)+Space(1)+'01:30:00'
 
后退
顶部