title: Can't declare variable in function MS SQL
body: <p>I'm newbie in SQL and trying to create function in MS SQL 2008R2, but can't declare variable inside function. What's wrong with this code?</p>
  
  <pre><code>CREATE FUNCTION denominator() RETURNS int
  BEGIN
      DECLARE @Count;
      -- Some logic here
  END;
  
  GO
  SELECT dbo.denominator()
  
  DROP FUNCTION denominator
  </code></pre>
  
  <p>I'm getting that kind of errors:</p>
  
  <pre><code>Msg 102, Level 15, State 1, Procedure denominator, Line 3
  Incorrect syntax near ';'.
  Msg 4121, Level 16, State 1, Line 1
  Cannot find either column "dbo" or the user-defined function or aggregate "dbo.denominator", or the name is ambiguous.
  </code></pre>