将SQLServer中的负数varchar和null值转换为decimal -相关文档
可以使用 ar get="_blank" href="http://www.volcengine.com/product/certificate-center">CAST 或 CONVERT ar get="_blank" href="http://www.volcengine.com/product/vefaas">函数将 v ar ch ar 类型转换为 de ar get="_blank" href="http://www.volcengine.com/product/cp">cimal 类型。对于 null 值,需要使用 ISNULL ar get="_blank" href="http://www.volcengine.com/product/vefaas">函数处理。
示例代码:
--创建一个示例表 CREATE T ar get="_blank" href="http://www.volcengine.com/product/datatester">ABLE test_t ar get="_blank" href="http://www.volcengine.com/product/datatester">able ( id INT, col1 V AR CH AR (10), col2 DE ar get="_blank" href="http://www.volcengine.com/product/cp">CIMAL(10,2)
--插入一些数据 INSERT INTO test_t ar get="_blank" href="http://www.volcengine.com/product/datatester">able VALUES (1, '100.00', 500.00); INSERT INTO test_t ar get="_blank" href="http://www.volcengine.com/product/datatester">able VALUES (2, '-50.00', 200.00); INSERT INTO test_t ar get="_blank" href="http://www.volcengine.com/product/datatester">able VALUES (3, 'NULL', 0.00);
--使用 ar get="_blank" href="http://www.volcengine.com/product/certificate-center">CAST ar get="_blank" href="http://www.volcengine.com/product/vefaas">函数将 v ar ch ar 转换为 de ar get="_blank" href="http://www.volcengine.com/product/cp">cimal,并处理 null 值 SELECT id, col1, ar get="_blank" href="http://www.volcengine.com/product/certificate-center">CAST(ISNULL(col1, '0.00') AS DE ar get="_blank" href="http://www.volcengine.com/product/cp">CIMAL(10,2)) AS col1_de ar get="_blank" href="http://www.volcengine.com/product/cp">cimal, col2 FROM test_t ar get="_blank" href="http://www.volcengine.com/product/datatester">able;
--使用 CONVERT ar get="_blank" href="http://www.volcengine.com/product/vefaas">函数将 v ar ch ar 转换为 de ar get="_blank" href="http://www.volcengine.com/product/cp">cimal,并处理 null 值 SELECT id, col1, CONVERT(DE ar get="_blank" href="http://www.volcengine.com/product/cp">CIMAL(10,2), ISNULL(col1, '0.00')) AS col1_de ar get="_blank" href="http://www.volcengine.com/product/cp">cimal, col2 FROM test_t ar get="_blank" href="http://www.volcengine.com/product/datatester">able;