title: Incorrect Syntax - SQL
body: <p>I am trying to update two fields in my table <code>tbl_prev_data</code> using subquery because I had to use the aggregate <code>SUM</code>. But I don't know why it says </p>
  
  <blockquote>
    <p>Incorrect Syntax near 't'`</p>
  </blockquote>
  
  <p>where <code>t</code> is a temp variable that holds the results of the subquery. Am I missing something ? Below is my query.</p>
  
  <pre><code>UPDATE tbl_prev_data
  SET Original_Value = t.Original_Value 
  SET Pre_Val = t.PreWDV
  FROM tbl_prev_data 
  INNER JOIN 
      (SELECT 
           Asset_Group_Code, 
           ISNULL(SUM(Original_Value),0) AS 'Original_Value', 
           ISNULL(SUM(Prev_Val),0) AS 'PreWDV' 
       FROM 
           tbl_Asset_Master 
       GROUP BY 
           Asset_Group_Code, DOP 
       HAVING 
           (YEAR(DOP) != YEAR(GETDATE()) AND MONTH (DOP) &gt; 3) t ON tbl_prev_data.Asset_Group_Code = t.Asset_Group_Code
  </code></pre>