SQL里怎么用Like搜时间字段

SQL数据表中有savetime(smalldatetime类型)字段,表中有两条记录,savetime值为:2005-3-8   12:12:00和2005-6-6   14:02:02

我用下面语句什么也搜不出来
select   *   from   soft   where   soft.savetime   like'%2005-3-8%'

SQL帮助中说:
"当搜索   datetime   值时,推荐使用   LIKE,因为   datetime   项可能包含各种日期部分。例如,如果将值   19981231   9:20   插入到名为   arrival_time   的列中,则子句   WHERE   arrival_time   =   9:20   将无法找到   9:20   字符串的精确匹配,因为   SQL   Server   将其转换为   1900   年   1   月   1   日上午   9:20。然而,子句   WHERE   arrival_time   LIKE   '%9:20%'   将找到匹配。"

后运行下面语句SELECT   soft.*,   CAST(soft.savetime   AS   varchar(20))   AS   strdatetime,  
发现
SQL把smalldatetime格试转成:
03     8   2005   12:12PM

我何用   like'%2005-3-8%'搜索到2005年3月8日所有的记录?



select   *  
from   soft  
where   datediff(d,soft.savetime,convert(datetime,'2005-3-8',120))=0

----
select   *  
from   soft  
where   convert(char(10),soft.savetime,120)='2005-03-08'

你可能感兴趣的:(like)