61090

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

Question:

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

Answer1:

Please check the link

<a href="https://stackoverflow.com/questions/6521354/convert-float-into-varchar-in-sql-server-without-scientific-notation" rel="nofollow">convert float into varchar in SQL server without scientific notation</a>

You can cast the float to varchar(max)

<a href="https://stackoverflow.com/questions/3715675/how-to-convert-float-to-varchar-in-sql-server" rel="nofollow">How to convert float to varchar in SQL Server</a>

Answer2:

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.

Recommend

  • Duplicate javascript for Codrops MULTI-LEVEL PUSH MENU
  • Storing large decimal numbers in Java
  • Shift operation implementation in java
  • VBA vlookup with defined range and file from other workbook
  • MS SQL Server 2008 :Getting start date and end date of the week to next 8 weeks
  • How to find data from last week in MySQL
  • Modifying files nested in tar archive
  • What does a hyphen at end of a term mean
  • Best way to produce 'colour correct' raster from a PDF or PS with ghostscript
  • Jquery UI Sortable, move item automatically
  • Reading space separated values file in c++ error
  • Identifier too long in Oracle
  • apply a javascript function to draggable copy
  • Aptana 3 remove bundle (jquery)
  • netsh acl setting (need alternative method - registry settings?)
  • How to 'create temp table as select' in Slick?
  • Eliminate partial duplicate rows from result set
  • pyodbc doesn't report sql server error
  • Z3: Convert between FP and BitVector?
  • How to handle images sent by a mobile device?
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Recording logins for password protected directories
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • How do I change content of ComboFieldEditor?
  • Pass value from viewmodel to script in zk
  • PHP - How to update data to MySQL when click a radio button
  • Counter field in MS Access, how to generate?
  • Resize panoramic image to fixed size
  • Volusion's generic SQL folder, functionality
  • Convert array of 8 bytes to signed long in C++
  • Weird JavaScript statement, what does it mean?
  • Do I've to free mysql result after storing it?
  • retrieve vertices with no linked edge in arangodb
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • SQL merge duplicate rows and join values that are different
  • Benchmarking RAM performance - UWP and C#
  • How do you join a server to an Active Directory (domain)?
  • Understanding cpu registers
  • coudnt use logback because of log4j
  • Add sale price programmatically to product variations