title: SQL Conditional Cast VARCHAR for FLOAT
body: <p>When I run the following query I get error "Cannot cast VARCHAR to FLOAT". The problem is some else on my team designed the DB a while back and put Milliseconds as varchar and sSometime the value isn't there so he put "NA" instead.</p>
  
  <p>Now when I cast the value for Milliseconds to take the AVE(), "NA" cannot be casted. Is there a way to define default value for "NA", like:</p>
  
  <pre><code>IF a.Milliseconds == "NA" 
       0
  ELSE
       CAST(a.Milliseconds AS FLOAT)
  
  
  
  SELECT 
    b.Date, 
    AVG(CAST(a.Milliseconds AS FLOAT)) AS Milliseconds,
  FROM Fields a
  INNER JOIN Cycles b
  ON a.CyclesId = b.Id
  GROUP BY b.Date
  
  Sample Data
  
  CyclesId | Milliseconds
  1        | 24.1557
  2        | 23.4886
  3        | NA
  </code></pre>