title: How to get a recursive list of functions within a procedure in SQL Server?
body: <p>I have a list of procedures and I can get a list of functions within those procedures. </p>
  
  <p>But I need to create a recursive way to see if there are functions within those functions. Here's how I started:</p>
  
  <pre><code>select  referencing_id,
          object_name(referencing_id) as referencing_object_name,
          object_name(sed.referenced_id) as referenced_object_name
  from    sys.sql_expression_dependencies as sed
  inner join sys.objects as obj
  on      sed.referencing_id = obj.object_id
  inner join #temp a
  on      a.procedure_name = object_name(referencing_id)
  where   referenced_entity_name in (select name
                                     from   sys.objects
                                     where  type_desc like '%function%')
  order by referencing_object_name
  </code></pre>
  
  <p>This code gives me a list of procedures and functions with them.</p>
  
  <p>How can I go a step further here to make sure I'm doing a recursive on the functions I found here so that if there are functions within those functions, I also see that too?</p>
  
  <p>NOTE: I don't need to do a recursive of the actual procedures. The list of procedures are already all the procedures I need. I'm only looking for the functions within functions.</p>
  
  <p>Thanks for the help!</p>