How to update multiple rows with multiple values? <p>Well, I have a table as this </p> <pre><code>id | idtable2|value | code |name | 1 | 3 |983 | 10 |Total | 2 | 4 |89 | 10 |type 4 | 3 | 5 |299 | 10 |type 5 | 4 | 6 |0 | 10 |type 6 | 5 | 7 |72 | 10 |type 7 | 6 | 8 |523 | 10 |type 8 | 7 | 4 | | 11 |percentaje4| 8 | 5 | | 11 |percentaje5| 9 | 6 | | 11 |percentaje6| 10 | 7 | | 11 |percentaje7| 11 | 8 | | 11 |percentaje8| </code></pre> <p>where I have my values and I need to have theirs percentages. These percentajes are based on values you could see. To get for example my rows with id 7 i could do it</p> <pre><code>declare @total int set @total=(select value from table where name='total') update table set value=(select value from table where code=1' and name='type 4')/@total </code></pre> <p>and I'll need do it for all my rows which are percentages, but this is a dinamic table. In another table I have a id, and a name (<code>table1.name it's equals to table2.name</code>) and table1 for every code (10,11) is going to have a name (from table2)</p> <p>How can I get this values? I tried with a query as it.</p> <pre><code>update ce set valor=valor/@total from #table1 ce inner join table2 m on ce.t2id=m.id where codigo=10 </code></pre> <p>but i got it update values with code 10, and not values with code 11. How could i do it?</p>