title: Why can't I run INSERT EXEC on a table variable in a T-SQL function?
body: <p>My function looks like this:</p>
  
  <pre><code>CREATE FUNCTION fn_FileSys_DirExists(@dirName AS nvarchar(260))
  RETURNS bit
  AS
  BEGIN
      DECLARE @dirExists int
      DECLARE @fileResults TABLE
      (
          file_exists int,
          file_is_a_directory int,
          parent_directory_exists int
      )
  
      INSERT @fileResults (file_exists, file_is_a_directory, parent_directory_exists)
      EXEC master.dbo.xp_fileexist @dirName
  
      SELECT @dirExists = file_is_a_directory FROM @fileResults
      RETURN @dirExists
  END
  </code></pre>
  
  <p>When I try and execute the above SQL, I get the following error:</p>
  
  <blockquote>
    <p>Invalid use of a side-effecting operator 'INSERT EXEC' within a
    function.</p>
  </blockquote>
  
  <p>I thought operations on a table variable in a function weren't considered side effecting operations?</p>