[英]How to convert Exist data from nvarchar to float in SQL Server
I have a table Overseas
in SQL Server take its data from an Excel sheet so numbers data sometimes is converted to text.我有一个 SQL Server 中的Overseas
表格从 Excel 工作表中获取数据,因此数字数据有时会转换为文本。 I want to perform an analysis so I have to convert this text to float each time I load this Excel file.我想执行分析,因此每次加载此 Excel 文件时,我都必须将此文本转换为浮动。
I created another table with datatype float
to copy the same table data to make analysis easier.我创建了另一个数据类型为float
表来复制相同的表数据以使分析更容易。
I tried this command;我试过这个命令; it works but the existing data doesn't get changed它有效,但现有数据没有改变
SELECT
CONVERT(FLOAT, REPLACE([SalesValue],',','') )[SalesValue]
FROM
Overseas
sql table sql表
For example : SalesValue
column is nvarchar
i want to convert it to float
and the data existing converted from nvarchar
to float
.. i want the output like this例如: SalesValue
列是nvarchar
我想将它转换为float
并且现有的数据从nvarchar
转换为float
..我想要这样的输出
Any help or another easier way ?任何帮助或其他更简单的方法?
Try below query : Use CAST method ,尝试以下查询:使用 CAST 方法,
SELECT CAST(REPLACE([SalesValue],',','') AS Float )[SalesValue]
FROM Overseas
最好将行从设计更改为浮动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.