将带有百分比(%)百分比的大十进制转换为小数点
我有以下数据需要转换为简单的小数。目前,它是varchar格式。数据在一个名为Commission%
佣金%(当前VARCHAR) | 佣金%V2(需要小数为小数) |
---|---|
的列中, 87.00000% | .87 |
95.00000% | .95 |
我尝试了以下内容:
CAST(CAST(CONVERT(FLOAT,REPLACE([Commission %], ''%'', '''')) / 100 AS DECIMAL(10,6)) as DECIMAL(10,6))
但是我收到以下错误消息错误转换错误。数据类型VARCHAR至数字。前几天我能够使用类似的东西,但是当时落后零的东西较少。
I have the following data that I need to convert to a simple decimal. Currently, it is in varchar format. The data is in a column called Commission%
Commission% (currently Varchar) | Commission% V2 (needs to be decimal) |
---|---|
87.00000% | .87 |
95.00000% | .95 |
I have tried the following:
CAST(CAST(CONVERT(FLOAT,REPLACE([Commission %], ''%'', '''')) / 100 AS DECIMAL(10,6)) as DECIMAL(10,6))
BUT I get the following error message Error converting data type varchar to numeric. I was able to use something similar the other day but there were fewer trailing zero's at the time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这几乎可以肯定是由于数据不良,这是您将数字存储为字符串时应该期望的。这是您识别它们的方式:
由于您现在说还有其他模式,因此仅仅这样做才能识别所有不良数据可能是有意义的:
然后将其清理。这应该是为什么您切勿将数字值存储在字符串列中的课程。
This is almost certainly due to bad data which is what you should expect when you store numbers as strings. Here is how you identify them:
Since you now say there are other patterns, it might make sense to just do this to identify all of the bad data:
Then clean it up. This should be a lesson in why you never store numeric values in string columns.