title: SQL Server : set a variable in CASE statement
body: <p>Is it possible to set a variable in a case statement? My code doesn't work. Thanks all.</p>
  
  <pre><code>CREATE PROCEDURE spReport
  @q1 INT,
  @q2 INT
  AS
  BEGIN
  
  -- Dates for the 2 different quarters to be viewed
  DECLARE @StartDateQ1 DATETIME
  DECLARE @EndDateQ1 DATETIME
  DECLARE @StartDateQ2 DATETIME
  DECLARE @EndDateQ2 DATETIME
  
  SELECT
  CASE @q1
      WHEN 1 THEN SET @StartDateQ1 = '20130401'
  END
  </code></pre>