SQL!急急急

sm521 2012-02-11 02:19:18
取出昨天以前的数据,且日期的时分秒在23点之前的。急急急!。忘高手指教
...全文
101 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
--取出昨天以前的数据,且日期的时分秒在23点之前的。急急急!。忘高手指教

create table #t(
id int identity(1,1),
dtime datetime
)
insert #t
select '2012-02-11 13:23:06' union all
select '2012-02-10 11:23:06' union all
select '2012-01-19 23:23:06' union all
select '2012-01-18 13:23:06' union all
select '2012-02-09 20:23:06' union all
select '2012-02-11 10:23:06'

select *from #t where dtime<GETDATE()-1 and DATEPART(hh,dtime) < 23

/*
id dtime
2 2012-02-10 11:23:06.000
4 2012-01-18 13:23:06.000
5 2012-02-09 20:23:06.000
*/

kingtiy 2012-02-11
  • 打赏
  • 举报
回复
select * from tb
where time <convert(varchar(10),convert(datetime,datediff(d,0,getdate()-1)),120)+' 23:00:00'
AcHerat 2012-02-11
  • 打赏
  • 举报
回复

select *
from date < getdate()-1
and datepart(hh,date) < 23
fengatj 2012-02-11
  • 打赏
  • 举报
回复
你的表里面有没有存储相应的时间字段?

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧