--选择日期在2004-09-03的数据 select * from tgoods where datediff(Day,dpubl,'2004-09-03')=0 select * from tablename where datediff(Day,日期字段,'2004-09-03')=0
假如是 '2005-07-25' 这一天: select * from fech where convert(varchar(10),thistime,120)='2005-07-25'
这样比采用 convert 好:select * from fech where datediff(Day,thistime,getdate())=0
---建立测试环境: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)=@dayexec pr1 4
select * from tgoods where datediff(Day,dpubl,'2004-09-03')=0
select * from tablename where datediff(Day,日期字段,'2004-09-03')=0
select * from fech
where convert(varchar(10),thistime,120)='2005-07-25'
where datediff(Day,thistime,getdate())=0
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)=@dayexec pr1 4