I have a column that I need to update with codes in a temp table.There is +/- 5 codes in the temp table. Each row in the table must be updated with one of the values in the temp table.
Example
id code
1 200
2 400
3 600
4 9000
5 800
6 200
7 400
8 600
9 9000
10 800
SQL Server Solution
This query will sequentially take the values from the
temptable and update the code in the example table in round robin fashion, repeating the values fromtempwhen required.If the ids are not sequential in either table, then you can
row_number()them first, e.g.The same technique (mod, row-number) can be used in other RDBMS, but the syntax will differ a little.