Is there a way to make a loop, something like a for or a while? Probably it's not even the way to solve the problem I have. So i'll write down the issue.
The problem I have is:
I have two tables, table1 have 2 primary keys, ID1 and ID2.
table2 uses ID1 and ID2 (foreign key) and an ID3.
(I'm ignoring the rest of the data, as I think it's unrelated to the issue.)
What I want to do, is to develop a SP to insert on table2. But I'm only receiving ID1 and ID3. What I want to is to insert the register for each different ID2 it exists on table1 with the same ID1 i'm getting.
That said, I'll write a little example to try to make it clearer.
Table1 has:
Code:
---TABLE1---
------------
ID1 ID2
1 10
1 20
And I want to call my_stored_procedure with ID1 and ID3 as parameters once.
Code:
call my_stored_procedure(ID1, ID3)
Let's say ID1 = 1 and ID3=101
As result of the call, table2 should be:
Code:
--------TABLE2--------
----------------------
ID1 ID2 ID3
1 10 101
1 20 101
Thanks