SQL Server 2008 - Alter column to Varchar from Float produces Scientific Notation

末鹿安然 提交于 2019-12-13 04:53:43

问题


I am having to change one of the columns in table which currently is Float to Varchar, but when I use alter command, it stores some of the longer numbers in Scientific Notation.

Can I avoid this?

If not, is there a way to easily update the table later to store the scientific notation as normal integer?

Thanks


回答1:


Please check the link

convert float into varchar in SQL server without scientific notation

You can cast the float to varchar(max)

How to convert float to varchar in SQL Server




回答2:


I have a workaround for this I have used in the past. Dan isn't far off, but just casting it won't work. You can alter the table by adding a new varchar column then using str and ltrim to update the new column from the old float column. Say your varchar column was varchar(50), use something like:

update YourTable set NewColumn = ltrim(str(OldColumn, 50))

str() converts to character data, ltrim() gets rid of any extra blanks on the left. You can then always get rid of the old column. Feels janky but should work for you.



来源:https://stackoverflow.com/questions/20102294/sql-server-2008-alter-column-to-varchar-from-float-produces-scientific-notatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!