我想用rmarkdown::render()
格式的CASE Statement
做出决定。但是无法使用time
格式做出正确的决定,因为我的时间范围的结束时间小于开始时间。让我用代码解释;
time
我也像下面这样在数据库中有表;
DECLARE @Startdate datetime
DECLARE @START_TIME time(0)
DECLARE @END_TIME time(0)
SET @Startdate='2020-04-15 16:00:00.000'
SET @START_TIME='15:30:00'
SET @END_TIME='01:29:59'
select
CASE WHEN CAST(@Startdate as time(0)) between @START_TIME and @END_TIME THEN 1 ELSE 0 END
我只想检查到达ID START_TIME END_TIME
1 05:30:00 15:29:59
2 15:30:00 01:29:59
值与datetime
完全匹配的时间。我不在乎约会的一部分。我该如何实现?
谢谢。
答案 0 :(得分:1)
一种方法是:
select case
when
(
@end_time >= @start_time
and cast(@startdate as time(0)) >= @start_time
and cast(@startdate as time(0)) <= @end_time
)
or (
@end_time < @start_time
and (
cast(@startdate as time(0)) >= @start_time
or cast(@startdate as time(0)) <= @end_time
)
)
then 1
else 0
end