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
foreach id in @id_string
   select * from helper_function(id) into #tmp
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