SQL Server 2008 - Alter column to Varchar from Flo

2019-09-02 09:11发布

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

2条回答
等我变得足够好
2楼-- · 2019-09-02 09:42

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.

查看更多
登录 后发表回答