title: How to replace a null value in a calculated field in a SQL Server query
body: <p>I want to replace a null value in a calculated column with 0 in a SQL Server query. </p>
  
  <p>This my query.</p>
  
  <pre><code>SELECT   
      Scenario, sum_amount + sum_cash + sum_tips AS total_earned 
  FROM
      Cash_Scenario 
  WHERE 
      scenario_Id = 5
  </code></pre>
  
  <p>I tried</p>
  
  <pre><code>SELECT   
      Scenario, sum_amount + sum_cash + sum_tips  AS total_earned,
      ISNULL(total_earned, 0) 
  FROM
      Cash_Scenario 
  WHERE
      scenario_Id = 5
  </code></pre>
  
  <p>But I am getting an error:</p>
  
  <blockquote>
    <p>Invalid column name 'total_earned' error. </p>
  </blockquote>
  
  <p>Essentially I want to return 0, if the total_earned value is null.</p>
  
  <p>Thanks</p>