I'm very new to SQL. More familiar with procedural programming
I currently have local variables such as names that change within a loop. However, I also execute a function that returns many rows. Right now I loop through each row to insert the values into a result table.
How do I put date in a table with values (name, cname, val1, val2) when I have multiple rows?
example case:
set @name = 'test'
select cname, val1, val2 from myfunc(@name)
returns:
-----------------------
| cname | val1 | val2 |
------------------------
|'atest'| 1.3 | 42.0 |
|'btest'| 1.58 | 6.87 |
------------------------
and I'd like result table (@restable) to be:
-----------------------------
name | cname | val1 | val2 |
-----------------------------
'test'|'atest'| 1.3 | 42.0 |
'test'|'btest'| 1.58 | 6.87 |
------------------------------
Note I still need @restable for more statements after this operation.
select @name, cname, val1, val2 from myfunc(@name)