SQL 查询前一天的数据

weilin_ai 2009-11-22 12:40:50
select * from Client_Table where InputDate=dateadd(dd,-1,getdate()) 取不到任何数据
select * from Client_Table where datediff(dd,InputDate,getdate())<=1 同样取不到任何数据
...全文
436 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixianxxx 2009-11-22
  • 打赏
  • 举报
回复
select * from Client_Table where cast(InputDate as datetime)=getdate()-1
icelovey 2009-11-22
  • 打赏
  • 举报
回复

select * from Client_Table where datediff(dd,cast(InputDate as datetime),getdate()) <=1
dawugui 2009-11-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 weilin_ai 的回复:]
select * from Client_Table where InputDate=dateadd(dd,-1,getdate()) 取不到任何数据
select * from Client_Table where datediff(dd,InputDate,getdate()) <=1 同样取不到任何数据
[/Quote]

如果这条取不到数据,就是你本身不存在昨天的数据.

select * from Client_Table where datediff(dd,InputDate,getdate()) <=1


你可以尝试看看:

select * from Client_Table where convert(varchar(10),InputDate,120) = '2009-11-21'
weilin_ai 2009-11-22
  • 打赏
  • 举报
回复
不出错,也得不到任何数据

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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