title: "Error converting data type varchar to float" message in SQL Server 2008
body: <p>I was given a script which will copy the contents of a table (from the sandbox) into another table (staging), but I keep getting "Error converting data type varchar to float" message.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>INSERT INTO First_DB.Orig_Table
  (CustomerNo, AccountGroupID, ComCode)
  
  SELECT A.CustomerNo, A.AccountGroupID, A.ComCode
  FROM Test_DB.DBO.viewCMMasterData A
  WHERE NOT EXISTS(SELECT B.CustomerNo
                   FROM First_DB.Orig_Table B
                   WHERE B.CustomerNo = A.CustomerNo)
  </code></pre>
  
  <p><strong><em>Test_DB.DBO.viewCMMasterData</em></strong> is under the Views folder and is tied with a table named <strong><em>dbo.cmMasterData</em></strong> which is also residing in the <strong><em>Test_DB</em></strong> database.</p>
  
  <p>As for the data types, </p>
  
  <p><strong>First_DB.Orig_Table</strong></p>
  
  <pre><code>CustomerNo (PK, varchar(10), not null)
  AccountGroupID (int, null)
  ComCode (varchar(4), null)
  </code></pre>
  
  <p><strong>Test_DB.DBO.viewCMMasterData</strong></p>
  
  <pre><code>CustomerNo (nvarchar(255), null)
  AccountGroupID (smallint, not null)
  ComCode (varchar(4), not null)
  </code></pre>
  
  <p>I tried using <strong><em>CAST()</em></strong> but to no avail. </p>
  
  <p>Please let me know if I still need to provide additional details.</p>