I just stuck to update the below table columns. Consider below scripts.
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')
The Result is
select * from @Table1
ID UserCount
----------- -----------
1 2
2 3
3 5
select * from @Table2
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
Based on the @Table1.UserCount value i need to update the Table2.IDRef value with @Table1.ID.
Expected Result is,
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
SQL Fiddle
Query:
Results: