title: SQL Converting Column type from float to varchar
body: <p>I'm trying to change the datatype in a column in a table from <code>Float</code> (null) to <code>Varchar(25)</code> (null). The largest float in the current data is 12 digits, but more digits may have to be added in the future, hence <code>varchar(25)</code>. </p>
  
  <p>The current data in the column is phone numbers. The change must be made to allow for preceding zeros.</p>
  
  <p>However, I'm having some difficulties doing this. </p>
  
  <p>I've tried the following:</p>
  
  <pre><code>ALTER TABLE Customer 
  ALTER COLUMN Phonenumber varchar(25)
  </code></pre>
  
  <p>This does not give me the desired result. </p>
  
  <p>For instance <code>1549779498</code> becomes <code>1.54978e+009</code></p>
  
  <p>Then I've tried something in the lines of this:</p>
  
  <ul>
  <li>Creating a new (temporary) column <code>PhonenumberVarchar</code> </li>
  <li>Converting and copying the data from one column to another </li>
  <li>Deleting the old column</li>
  <li>Renaming the new column to the old name</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>ALTER TABLE Customer 
  ADD PhonenumberVarchar varchar(25)
  
  UPDATE Customer 
  SET PhonenumberVarchar = STR(Phonenumber, 12, 0)
  
  ALTER TABLE Customer 
  DROP COLUMN Phonenumber
  
  EXEC sp_rename 'Customer.PhonenumberVarchar', 'Phonenumber', 'COLUMN'
  </code></pre>
  
  <p>This doesn't work either:</p>
  
  <blockquote>
    <p>Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , >, >= or when the subquery is used as an expression.</p>
  </blockquote>
  
  <p>And now it's late and my head hurts... </p>
  
  <p>Can anyone help?</p>
  
  <p>NOTE:</p>
  
  <p>The table is rather large, some 1.5 million rows, so performance can be an issue. </p>
  
  <p>Using SQL Server. </p>