Gar*_*ary 3 sql t-sql sql-server case-when
我正在尝试根据以下2个条件从连接表中检索记录:
Where if(b.enddate is null)
a.starttime >= b.starttime
else
a.starttime >= b.starttime and a.endtime <= b.endtime
Run Code Online (Sandbox Code Playgroud)
我看过使用case的例子,但结果不是我想要的.请帮助我将此条件转换为正确的sql格式.
您不需要使用case表达式,这可以使用ORin WHERE子句来完成
... Where
( b.enddate is null and a.starttime >= b.starttime)
or
( b.enddate is not null and a.starttime >= b.starttime and a.endtime <= b.endtime)
Run Code Online (Sandbox Code Playgroud)