title: Updating sql table with results from left join (sql server)
body: <p>I need help with a SQL server query. I'm trying to update an existing table (#Masterfile), based on the results of left joining the table with another outside source (table 2). Row 6 is basically a flag that says whether the ID exists in table b or not. I am new to sql (just started learning a couple of weeks ago) so my syntax is probably very basic. I left joined the #Masterfile with the new table of interest (Table 2) and then select the result (and update the column6_flag). </p>
  
  <p>However, I get error, identifying the statement (, a.column6_flag = case when x.column9 is not NULL  then 1 else 0 end) as the culprit. Any help would be much appreciated!!! I tried looking at case when syntax again but can't identify why it's yielding error. When I comment out the case when portion of the query, it works.</p>
  
  <p>Thanks again!</p>
  
  <pre><code>--Insert into #MasterFile 
   select distinct
       a.column1
       , a.column2
       , a.column3
       , a.column4
       , a.column5
       , a.column6_flag = case when x.column9 is not NULL  then 1 else 0 end
       , a.column7
       , x.column9
  from 
      #Alldata a
  left join 
      (select m.column9
       from #Masterfile m
       left join table2 n on m.id = n.id) x on a.id = x.id
  </code></pre>