title: Invalid use side-effecting operator Insert within a function
body: <p>I have the following code in my sql function:</p>
  
  <pre><code>if @max_chi &gt; -999
  begin
      INSERT INTO CH_TABLE(X1, X2, VALUE)
      VALUES(cur_out.sessionnumber, maxpos, max_chi)
  
      commit
  end
  </code></pre>
  
  <p>The following is a SQL Server 2008 Query and it gives me an error:</p>
  
  <blockquote>
    <p>Invalid use of a side-effecting operator 'INSERT' within a function.</p>
  </blockquote>
  
  <p>Why am I not allowed to do this? What can I do to fix this?</p>