我理解MSSQL没有LEAST功能,并且CASE提供了一个合理的替代方案,但是,出于某种原因,我正在努力使其工作。
目前的代码是:
SELECT CAST(CAST(@QueryStartDate AS DATE) AS DATETIME) + CAST(tt.Time as datetime) as [Time],
COALESCE(td.[Max Time],0) AS [Max Time]
我正在尝试改为:
SELECT CAST(CAST(@QueryStartDate AS DATE) AS DATETIME) + CAST(tt.Time as datetime) as [Time],
CASE [Max Time]
WHEN td.[Max Time] > 9.00
THEN 9.00 ELSE COALESCE(td.[Max Time],0)
END
但似乎无法让它发挥作用!如果有人能让我知道我哪里出错了,我将不胜感激。感谢
答案 0 :(得分:0)
select cast(null as float) as [Max Time] into #tmp
insert into #tmp select 3.0
insert into #tmp select 12.0
select * from #tmp
select case
when coalesce([max time], 0.0) < 9.0 then 9.0
else [Max Time]
end
from #tmp