在以下情况下,使用t-sql大小写将十进制值设置为基于基础数字的特定值:
在T-Sql中,如何使用case将基础数字的十进制值设置为基于条件的值?举例说明: 列saleprice用于价格(2位小数),例如129.99或19.99 我想选择SalesPrice,但结果略有调整:在以下情况下,使用t-sql大小写将十进制值设置为基于基础数字的特定值:,sql,sql-server-2008,decimal,case,rounding,Sql,Sql Server 2008,Decimal,Case,Rounding,在T-Sql中,如何使用case将基础数字的十进制值设置为基于条件的值?举例说明: 列saleprice用于价格(2位小数),例如129.99或19.99 我想选择SalesPrice,但结果略有调整: 如果SalesPrice>=100,小数点应为.00(129.99-->130.00) 如果SalesPrice19.95) 谢谢 假设所有值均为正值,以下是一种方法: update t set SalesPrice = (case when SalesPrice >= 100
- 如果SalesPrice>=100,小数点应为.00(129.99-->130.00)
- 如果SalesPrice<100,小数点应为.95(19.99-->19.95)
谢谢 假设所有值均为正值,以下是一种方法:
update t
set SalesPrice = (case when SalesPrice >= 100 then floor(SalesPrice) + 1
when SalesPrice < 100 then floor(SalesPrice) + 0.95
end)
where (SalesPrice - floor(SalesPrice)) >= 0.9;
where
子句保证存在十进制金额。例如,这可以防止21
变成21.95
。嗯。。。您的四舍五入规则不清楚,什么时候进行四舍五入,什么时候进行四舍五入?好问题,如果12.01-->11.99,如果12.51-->11.99,如果12.95-->12.95,如果12.96-->12.95。希望这是有帮助的。谢谢
update t
set SalesPrice = (case when SalesPrice >= 100 then floor(SalesPrice) + 1
when SalesPrice < 100 then floor(SalesPrice) + 0.95
end)
where SalesPrice > floor(SalesPrice);