0
我需要检查使用CTE参数检查日期时间变量的条件。无法检查SQL Server 2008中的日期时间条件
例子:
create table testt
(
coldate date,
coltime datetime,
colseconds integer
)
插入一些记录:
insert into testt values('2014-08-02','10:00:00',50);
insert into testt values('2014-08-02','11:08:08',120);
insert into testt values('2014-08-02','11:08:55',160);
insert into testt values('2014-08-03','09:00:15',180);
insert into testt values('2014-08-04','11:00:10',600);
insert into testt values('2014-08-04','11:05:50',320);
CTE:
with t(cdate,ctime,exittime ,starttime)
as
(
Select coldate ,coltime ,
DATEADD(SS,colseconds ,coltime) as CETime,
coltime as CSTime
from testt
)
select exittime,starttime from t
where ctime > starttime and ctime < exittime
and cdate = '2014-08-02'
但是当我使用下面的查询我会得到结果:通过给予直接值
with t(cdate,ctime,exittime ,starttime)
as
(
Select coldate ,coltime ,
DATEADD(SS,colseconds ,coltime) as CETime,
coltime as CSTime
from testt
)
select exittime,starttime from t
where ctime > '11:08:55' and ctime < '11:10:00'
and cdate = '2014-08-02'
没有得到如何转换它?
这个问题无法理解。请尝试重新房地产。你想达到什么目的?怎么样?什么是失败? – JotaBe 2014-09-01 11:32:45
到目前为止,你的问题没有意义。最后一个查询将'ctime'与特定值进行匹配,而前一个查询将其与相同数据集的列进行匹配。请解释你正在尝试做什么。 – 2014-09-01 12:04:28