I'm working with a legacy system where a stored procedure is called and dozens (literally) of variables are passed in. The data needs to be processed the same way but currently I have to copy/paste the code with a numerical change dozens of times.
What I want to do is put the data into a table variable and use that to create a loop that runs the same code but with a different row from the table.
So, in summary, I have variables
TypeA1,
TypeB1,
TypeC1,
TypeD1,
etc.
That I want to store temporarily as
| Index | TypeA | TypeB | TypeC | TypeD |
|---|---|---|---|---|
| 1 | TypeA1 | TypeB1 | TypeC1 | TypeD1 |
| 2 | TypeA2 | TypeB2 | TypeC2 | TypeD2 |
This should allow me to loop, pull a row into generic variables, and execute the repeated process.
Do you mean that you'd process values (1, 'TypeA1'), (1, 'TypeB1'), (2, 'TypeA1') ... in the executed loop?
No, more process it as (1, TypeA, TypeB, SomeValue, AnotherThing). I have a hundred of these to process, but I get the values separately and only the numeric value of the variable tells me which one it is.
I have lots of variables that are only grouped by number. I need to be able to do the same task to each numbered group of variables i.e.
insert into X
values (1, TypeA, TypeB, TypeC, TypeD, Something, AnotherThing)
The calling app can't do the loop because it is old and a black box. I can't get under the hood.