title: execute sp_executesql error
body: <p>I have a formula.And formula is a nvarhcar like '2+5+8/3'</p>
  
  <p>I want to make a function that after calculated my formula give me a result like</p>
  
  <pre><code>alter FUNCTION Calculate(@Formula NVARCHAR(100))
  RETURNS FLOAT
  AS
  BEGIN
  DECLARE @Result2 FLOAT,@Query NVARCHAR(50)
  SET @Query=N'select @Result='+@Formula
  execute sp_executesql @Query ,N'@Result float output',@Result=@Result2 OUTPUT
  RETURN @Result2
  END
  </code></pre>
  
  <p>function create successfully but I use the function</p>
  
  <p>select dbo.Calculate('2+5+9')
  I get a error that
  'Only functions and extended stored procedures can be executed from within a function.'
  How can make a function like this?Thanks a lot</p>
  
  <p>Thanks your answer but I will use it in a select query,
  my data like that</p>
  
  <pre><code>Name Formula Result
  dd    2+3+5
  gg    1+4+7
  hh    2*8
  jj    3*9
  Kl    8*9
  </code></pre>
  
  <p>I have to calculate Result column a select
  like</p>
  
  <p>select
  Name,dbo.Calculate(Formula) as Result
  Is there another way to make it</p>