如何在SQL Server的where子句中传递datetime字段的值

|| 大家好, 我创建了一个存储过程,其中在选择查询中有datetime字段。 这是我的查询
select * from tablename where publishdate like \'%03/10/2011%\'
这可能吗,或者我应该如何构成查询?我的目标是查询应返回2011年3月10日的记录     
已邀请:
        使用转换
select * from tablename where convert(varchar(10), publishdate, 103) = \'03/10/2011\'
    
        尝试
select * from tablename where day(publishdate) = 10 And Month(publishdate) = 3
And Year(publishdate) = 2011 --Let the required date be 10th March 2011
希望能有所帮助。     
        最好的方法是:
Select * 
from   tablename
Where  publishdate >= \'20110310\'
       and publishdate < \'20110311\'
通过分离这样的条件,可以允许SQL Server在publishdate列上使用索引(如果存在索引)。我显示的查询将使用超快速索引查找而不是扫描,从而获得更好的性能。     

要回复问题请先登录注册