title: SQL Server - Must declare the scalar variable
body: <p>I am trying to declare these values and use execute them to get a specific values of an attribute in a table. However everytime I am time trying to set @test and @columnPeriod it gives me the error <em>Must declare the scalar variable "@test"</em> or <em>Must declare the scalar variable "@columnPeriod"</em></p>
  
  <pre><code>DECLARE @columnPeriod VARCHAR(MAX), @test INT;
  SET @test = 2015;
  SET @columnPeriod = 'SELECT Period FROM Courses WHERE year = ' + @test + '';
  </code></pre>