如何在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列上使用索引(如果存在索引)。我显示的查询将使用超快速索引查找而不是扫描,从而获得更好的性能。     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...