title: Insert into table based on case...when statement
body: <p>This is what 1st I want to do:</p>
  
  <p>I have one table(T1) having account ID and wanted to insert a flag into another table (T2) based on the account ID present in table T1 or not.</p>
  
  <p>2nd:</p>
  
  <p>And, later I want to update the flag also [based on account id present in T1 or not]</p>
  
  <p>I'm trying it like this:</p>
  
  <pre><code>Insert into T2 (...,flag)
  select distinct ...,
  case
  When (insert into T2 from T1 where T1.accountID not in 
  (select accountID   from t2)) then 'Y'
  When (insert into T2 from T1 where T1.accountID in 
  (select accountID from  t2)) then 'N'
  from
  T3 join T2
  </code></pre>
  
  <p>basically, in CASE, I'm trying to get the flag ("Y" or "N") and inserting into T2. Note: I need to calculate the flag, as I do not have flag column in T1. </p>
  
  <p>Hope this make sense.</p>
  
  <p>Is this correct way of doing? Please help.</p>