title: how to deal with "Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)."
body: <p>i was asked to Create script that will expect whoever runs it to provide an employee id. Locate all employees that the provided employee supervises in any depth. </p>
  
  <p>My code is : </p>
  
  <pre><code>CREATE FUNCTION [dbo].[GetNames] (@V uniqueidentifier)  
  RETURNS @OldNames TABLE (EMP_NAME varchar(50))
   AS 
  BEGIN
      DECLARE @master uniqueidentifier
      SET @master=(SELECT EMP_Supervisor FROM Employee WHERE EMP_ID=@v)
      IF @master=NULL return
  
      INSERT INTO @OldNames(EMP_NAME)
          SELECT (SELECT EMP_NAME FROM Employee WHERE EMP_ID = @master)
          FROM Employee
          UNION
          SELECT EMP_NAME FROM GetNames(@master)
       RETURN
  END
  </code></pre>
  
  <p>And when i want to see if it works, i execute this :</p>
  
  <pre><code>SELECT * from GetNames('561e2d88-a747-460f-99e1-cfb1d3d8ca5c')
  </code></pre>
  
  <p>where "<em>561e2d88-a747-460f-99e1-cfb1d3d8ca5c</em>" is an ui of an employee and i get this as an exception:</p>
  
  <blockquote>
    <p>Maximum stored procedure, function, trigger, or view nesting level
    exceeded (limit 32).</p>
  </blockquote>
  
  <p>can you please help me? Thanks in advance!! </p>