multiple selects from a function into a temp table

  • I have a function helper_function which I want to reuse
  • Passing a parameter to another function f_union_helper_functions where a string id_string with ids is passed
  • Split this string and iterate through all ids
  • calling the function and adding result to a temp table
  • return select from this table

Pseudo code:

create function f_union_helper_functions
(
@id_string varchar,
...
return table as
return
(
...
foreach id in @id_string
begin
   select * from helper_function(id) into #tmp
end
select #tmp
)

This code above is far from being complete/correct. I just want to combine the concepts of iterating and union into a temp table and return it. How can I achieve that?

1 answer