读书人

SQL 2005 查询时间有关问题

发布时间: 2012-09-17 12:06:51 作者: rapoo

SQL 2005 查询时间问题
字段名:tempTime 类型:smalldatetime 值:2012-08-08 12:00:12

在使用查询语句时,查询不出来。例:select * from temp tempTime like ('2012-08-088') .
各种方法测试过,发现我问题出现在“-”上,各位高手,求指导^.^

[解决办法]

SQL code
select * from temp where convert(varchar(10),tempTime,120)='2012-08-08';
[解决办法]
http://msdn.microsoft.com/zh-cn/library/ms187928(v=SQL.90).aspx
[解决办法]
SQL code
declare @time date = '2012-08-08'select * from temp where tempTime > @time and tempTime >= @time <= DATEADD(DAY,1,@time) 

读书人网 >SQL Server

热点推荐