title: SQL Server: CREATE FUNCTION with declare variables inside
body: <p>I would like to create a <code>function</code> in <code>SQL Server</code>.</p>
  
  <p>In this function, I need to define some <code>variables</code> and then use it in the SELECT.</p>
  
  <p>SQL looks like below:</p>
  
  <pre><code>CREATE FUNCTION [dbo].[MyFussnction]  
  (
      @path [nvarchar](10)
  )
  RETURNS TABLE
  
  BEGIN
      DECLARE @xx varchar(50);
      SET @xx = 'Windows%';
  RETURN 
      SELECT * FROM MyTable WHERE DataPath LIKE @path AND XX LIKE @xx;
  END
  </code></pre>
  
  <p>But, it is not able to be created and the error says:</p>
  
  <pre><code>Msg 102, Level 15, State 31, Procedure MyFussnction, Line 12 [Batch Start Line 0]
  Incorrect syntax near 'BEGIN'.
  </code></pre>