title: how to write reflection function on SQL
body: <p>i have a table </p>
  
  <pre><code>Id    PId   code 
  12    10    abca
  13    12     wwr
  14    13     sdf
  15    14     aba
  16    15     wqe
  </code></pre>
  
  <p>i need to  replace the  PIDs with parent ID Like</p>
  
  <pre><code>Id    PId   code 
  12    10     abca
  13    12     wwr
  14    12     sdf
  15    12     aba
  16    12     wqe
  </code></pre>
  
  <p>this is my basic need to replace with all child PId 
  i think we need to  write a recursive function  and need to replace 
  im using sql server 2008 rs , tell me the best way how can i achieve this </p>