title: SQL - Error converting data type varchar to numeric
body: <p>I have data in a table that has decimals and stored as a varchar type data.  I need to place that data into another table with column that is data type of decimal(18,5)</p>
  
  <p>I get error:</p>
  
  <pre><code> Error converting data type varchar to numeric
  </code></pre>
  
  <p>The problem is with this <code>Share</code> column </p>
  
  <p>Query I have is</p>
  
  <pre><code>SELECT IFS.Bin,CFL.CUSIP,IFS.[FROM], 
  --IFS.Shares 
  --SUM(isnull(cast(IFS.Shares as money),0))
  --CAST(isnull(IFS.Shares,0) AS VARCHAR(30))
   Shares =
    Convert(
       DECIMAL(18,5), 
       CASE
       WHEN IFS.Shares LIKE '%[^0-9]%' THEN IFS.Shares --NULL
       ELSE IFS.Shares
       END)
  FROM 
  mfclearing.ICE.ImportFileStaging IFS INNER JOIN 
  mfclearing.Production.ClearingFundList CFL ON 
  IFS.[From] = CFL.NasdaqSymbol
  </code></pre>
  
  <p>So if I try to only use  <code>IFS.Shares</code> that doesn't work, I was trying some other SUM and CAST , but the last thing is that I'm trying to do is that Shares = Convert ..... </p>
  
  <p>Should not be too relevant to this, but I do want to do an insert into and so I do have an insert statement right above that Select statement
  <code>INSERT INTO [InterclassExchangeBatchDetails](Bin,FromCusip,FromSymbol,Shares)</code></p>
  
  <p>The data that I'm working with for reference that is causing the problem, here is a sample of it</p>
  
  <pre><code>521.92100000000005
  9906.8510000000006
  542.529
  1043.8409999999999
  3129.0839999999998
  5285.4120000000003
  104.367
  126.98
  332.02499999999998
  530.12300000000005
  575.57799999999997
  895.56899999999996
  1052.9349999999999
  1167.0619999999999
  1180.9939999999999
  1630.8030000000001
  247.232
  2136.2040000000002
  667.95500000000004
  947.78599999999994
  148.36000000000001
  223.994
  238.42699999999999
  255.25700000000001
  257.56999999999999
  259.70600000000002
  317.90199999999999
  317.90199999999999
  317.90199999999999
  360.59199999999998
  366.84399999999999
  374.35000000000002
  376.90199999999999
  393.11500000000001
  397.37200000000001
  399.47699999999998
  449.72699999999998
  463.60899999999998
  474.68599999999998
  488.11599999999999
  491.245
  504.67399999999998
  509.97899999999998
  530.47199999999998
  535.93299999999999
  537.69799999999998
  549.40599999999995
  552.41700000000003
  581.32600000000002
  608.05100000000004
  </code></pre>