【发布时间】:2018-11-30 15:26:58
【问题描述】:
-- Transact SQL: case when 1=1 then 0.5 else ceiling(sh) end /* returns 1 (!) why? */
declare @T table (h decimal(2,1))
insert @T (h) values (1.0)
select
case when 1=1 then 0.5 else ceiling(sh) end /* returns 1 (!) why? */
from @T T1
join (select sum(h) as sh from @T )T2 on 1 = 1
【问题讨论】:
-
它正在转换为 int
-
因为 ceiling(sh) 返回 int —— 在 case 两边不同的情况下,它将“升级”为 int。在他的回答中查看@JuanCarlosOropeza 代码
-
其实返回十进制(38,0)
-
@Hogan 它不返回 int 并且 int 没有比十进制更高的数据类型优先级
-
哦,那是
CEILING,当然是numeric(38,0)
标签: sql-server join sum case ceil