I have a table that looks like this
[UniqueID]-[1]-[2]-[3]-[etc... to 250
------------------------------
00000A | 0 | 0 | 1 |
00000B | 0 | 1 | 0 |
00000C | 0 | 1 | 1 |
I pivoted that table from another table with two columns, the unique ID and the number (1, 2, 3, etc.)
I have another table which has two columns, a number and an elimination. For example, if the number is 2 and the elimination is 3, I would take the unique ID 00000C, go to column 3, and change the 1 to a 0.
In the past, I have manually written:
UPDATE [TABLE] SET [3] = 0 WHERE [2] = 1
I need to do this about 150 times, so it would be much more concise to write a query to read from the second table to modify the first. Additionally, when I have to make changes, I will only need to modify the table instead of making changes to the query itself.
I know I can probably do this by pivoting the second table and using Dynamic SQL, and I will do that if I have to, but I'm wondering if any of you have some other ideas to solve this problem.
Basically, what I am looking to do is this:
UPDATE [TABLE] SET [(SELECT elim FROM ElimTbl)] = 0
WHERE [(SELECT num FROM ElimTbl)] = 1
I know that's invalid, but I'm hoping someone has a better idea.
Thank you for your time!