日期:2014-05-17 浏览次数:20559 次
if OBJECT_ID('t') is not null
drop table t
go
create table t(d datetime)
insert into t
select cast('2013-05-01' as datetime) as d
union all
select cast('2013-05-10' as datetime)
/*
1.
通过查询计划能看出,SQL Server把下面的查询转化成了:
select * from t where d >= convert(datetime,2013/5/1,0) and d <= convert(datetime,'2013/6/24',0)
也就是查询条件:
d >= convert(datetime,2013/5/1,0) and d <= convert(datetime,'2013/6/24',0)
进一步转化:
d >= '1901-02-07 00:00:00.000' and d <= 2013-06-24 00:00:00.000
这样就能查询出结果集。
*/
select *
from t
where d between convert(datetime,2013/5/1) and convert(datetime,'2013/6/24')
/*
2.
通过查询计划能看出,SQL Server把下面的查询转化成了:
select * from t where d >= convert(datetime,2013/5/1,0) and d <= convert(datetime,2013/6/24,0)
也就是查询条件:
d >= convert(datetime,2013/5/1,0) and d <= convert(datetime,2013/6/24,0)
进一步转化:
d >= '1901-02-07 00:00:00.000' and d <= '1900-01-14 00:00:00.000'