cast or convert a float to nvarchar?

前端 未结 7 1157
醉话见心
醉话见心 2021-02-03 22:02

I need to select from one column of datatype float and insert it in another column as nvarchar.

I tried to cast it: cast([Column_Name] as nvarchar(50))

7条回答
  •  梦如初夏
    2021-02-03 22:38

    DECLARE @MyFloat [float]
    
    SET @MyFloat = 1000109360.050
    
    SELECT REPLACE (RTRIM (REPLACE (REPLACE (RTRIM ((REPLACE (CAST (CAST (@MyFloat AS DECIMAL (38 ,18 )) AS VARCHAR( max)), '0' , ' '))), ' ' , '0'), '.', ' ')), ' ','.')
    

提交回复
热议问题