怎样取出同一天的记录?

gaoxiaopai 2005-07-26 10:33:58
我表fech中有data型字段thistime,我想取出同一天的记录,给个例子,谢谢!我是新手,别笑我哈
...全文
169 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
phantomMan 2005-07-26
  • 打赏
  • 举报
回复
这样比采用 convert 好:

select * from fech
where datediff(Day,thistime,getdate())=0
gaoxiaopai 2005-07-26
  • 打赏
  • 举报
回复
日期不要固定,我要取出的是当前这一天,就是系统时间的这一天
phantomMan 2005-07-26
  • 打赏
  • 举报
回复
假如是 '2005-07-25' 这一天:
select * from fech
where convert(varchar(10),thistime,120)='2005-07-25'
点点星灯 2005-07-26
  • 打赏
  • 举报
回复
--选择日期在2004-09-03的数据
select * from tgoods where datediff(Day,dpubl,'2004-09-03')=0


select * from tablename where datediff(Day,日期字段,'2004-09-03')=0
gaoxiaopai 2005-07-26
  • 打赏
  • 举报
回复
写错了
我表fech中有datetime型字段thistime
GRLD8888 2005-07-26
  • 打赏
  • 举报
回复
---建立测试环境:

create table fech (id int,thistime datetime)

insert fech select 1,'2001-10-01'
union all select 2,'2001-10-01'
union all select 3,'2001-10-03'
union all select 4,'2001-10-03'
union all select 5,'2001-10-04'
union all select 6,'2001-10-01'

select * from fech


select * from fech where datepart(dd,thistime)=1

如果你频繁这样查询的话,建议你创建一个存储过程。

create proc pr1
@day int
as
select * from fech where datepart(dd,thistime)=@day

exec pr1 4
QQ503503 2005-07-26
  • 打赏
  • 举报
回复
同意 phantomMan

34,590

社区成员

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

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