4 个解决方案
#1
select (case when A-cast(A as int)>0.5 then cast(cast(A as int) as decimal)+0.5
else cast(cast(A as int) as decimal) end ) as col1
from t1
#2
这个肯定要你自己写了,写个自定义函数即可
#3
DECLARE @T TABLE(Col1 DECIMAL(18,2))
INSERT INTO @T SELECT 1.78
INSERT INTO @T SELECT 2.35
INSERT INTO @T SELECT 2.56
SELECT CAST(Col1/0.5 AS INT)*0.5 FROM @T
/*
1.5
2.0
2.5
*/
#4
#3的方法很好
#1
select (case when A-cast(A as int)>0.5 then cast(cast(A as int) as decimal)+0.5
else cast(cast(A as int) as decimal) end ) as col1
from t1
#2
这个肯定要你自己写了,写个自定义函数即可
#3
DECLARE @T TABLE(Col1 DECIMAL(18,2))
INSERT INTO @T SELECT 1.78
INSERT INTO @T SELECT 2.35
INSERT INTO @T SELECT 2.56
SELECT CAST(Col1/0.5 AS INT)*0.5 FROM @T
/*
1.5
2.0
2.5
*/
#4
#3的方法很好