更新时间:2023-02-06 11:39:27
我需要将值 22.30 转换为 0.223.
I need to convert the value 22.30 to 0.223.
你需要除以100.0,然后DECIMAL(4, 3)
就可以了
You need to devide it by 100.0, then DECIMAL(4, 3)
will be OK
DECLARE @Value DECIMAL(4, 3) = 22.3 / 100.0;
SELECT @Value
退货:
0.223
因此,您需要先UPDATE
您的表,然后ALTER
[BB Percent]
列.
So, you need to UPDATE
your table first, then ALTER
the [BB Percent]
column.
简单的方法是:
DECIMAL(4, 3)
.--First step
ALTER TABLE badv2018
ADD New DECIMAL(4, 3);
--Second step
UPDATE badv2018
SET New = [BB Percent] / 100.0;
--Third step
ALTER TABLE badv2018
DROP COLUMN [BB Percent];
--The last step
EXEC sp_rename 'badv2018.New', 'BB Percent', 'COLUMN';
享受吧!
更新:
您也可以添加一个计算列并保留[BB Percent]
列,这样可以确保您获得真实数据和计算出的数据.
You can also add a computed column and leave the [BB Percent]
column, this way will ensure you can get the real data and the computed one.
ALTER TABLE badv2018
ADD New AS CAST([BB Percent] / 100.0 AS DECIMAL(4, 3));