title: SQL Server : Must declare the scalar variable
body: <p>I need to declare globally variable as counter</p>
  
  <pre><code>DECLARE @counter int
  SET @counter = 0;
  </code></pre>
  
  <p>And then use a stored procedure, but it always tells me that <code>@counter</code> must be declared as scalar variable</p>
  
  <pre><code>CREATE OR ALTER PROCEDURE proc_counter_type 
       @type NVARCHAR(15), 
       @dateFirst DATE,
       @dateSecond DATE
  AS
      SELECT @counter = COUNT(title_id)
      FROM books
      WHERE type = @type AND (datum BETWEEN @dateFirst AND @dateSecond)
  </code></pre>