title: How to update the table records which are dependent on another table
body: <p>I just stuck to update the below table columns. Consider below scripts.</p>
  
  <pre><code>declare @Table1 Table  ( ID int Identity(1,1), UserCount int )
  insert into @Table1 (UserCount) values (2),(3),(5)
  declare @Table2 Table ( ID int Identity(1,1), Name varchar(10), IDRef int null)
  insert into @Table2 (Name) values ('p1'),('p2'),('p3'),('p4'),('p5'),('p6'),('p7'),('p8'),('p9'),('p10')
  </code></pre>
  
  <p>The Result is </p>
  
  <p>select * from @Table1</p>
  
  <pre><code>ID          UserCount
  ----------- -----------
  1           2
  2           3
  3           5
  </code></pre>
  
  <p>select * from @Table2</p>
  
  <pre><code>ID          Name       IDRef
  ----------- ---------- -----------
  1           p1         NULL
  2           p2         NULL
  3           p3         NULL
  4           p4         NULL
  5           p5         NULL
  6           p6         NULL
  7           p7         NULL
  8           p8         NULL
  9           p9         NULL
  10          p10        NULL
  </code></pre>
  
  <p>Based on the <code>@Table1.UserCount</code> value i need to update the <code>Table2.IDRef</code> value with <code>@Table1.ID</code>.</p>
  
  <p>Expected Result is,</p>
  
  <pre><code>ID          Name       IDRef
  ----------- ---------- -----------
  1           p1         1
  2           p2         1
  3           p3         2
  4           p4         2
  5           p5         2
  6           p6         3
  7           p7         3
  8           p8         3
  9           p9         3
  10          p10        3
  </code></pre>