title: Populate second Table based on First Table
body: <p>TableA, TABLE B.</p>
  
  <p>TableA has below records.</p>
  
  <pre>
  id  Name    Address phone   RecordType  ProcessStatus
  1   ABC      HYD    123      INSERT           4
  2   PQR      IND    111      INSERT           4
  1   ABC      NULL   6780     UPDATE           3
  </pre>
  
  <p>I want to select RECORD_TYPE='UPDATE' type only. If any value of RecordType=UPDATE has NULL value it should compare it with INSERT TYPE record and bring the value instead of populating NULL. I have to populate the Table B in a way that it should reflect as below.</p>
  
  <pre>
  id  Name    Address phone   RecordType  ProcessStatus
  1   ABC      HYD    6780     UPDATE           3
  </pre>
  
  <p>Below is what i have tried. </p>
  
  <pre><code>SELECT COALESCE(A.ID,B.ID),
  COALESCE(A.ADDRESS,B.ADDRESS),
  COALESCE(A.PHONE,B.PHONE),
  COALESCE(A.RECORD_TYPE,B.RECORD_TYPE),
  COALESCE(A.STATUS,B.STATUS)
  
   FROM #TEMP A INNER JOIN #TEMP B
  ON A.ID=B.ID
  WHERE A.RECORD_TYPE='UPDATE'
  </code></pre>
  
  <p>And below is what i am getting.</p>
  
  <pre>
  ID  ADDRESS PHONE   RECORD_TYPE STATUS
  1   ABC      123    UPDATE         3
  1   ABC     NULL    UPDATE         3
  </pre>