title: SQL Server : declaring a cursor with a PARAMETER
body: <p>This question is mostly to confirm a (sad) conclusion I reached after some googling.</p>
  
  <p>I need to use a <code>CURSOR</code> in SQL Server 2012 in which there is a <code>WHERE</code> clause that depends on a parameter, something like:</p>
  
  <pre><code>...
  DECLARE @MyParam INT ;
  
  DECLARE My_Cur CURSOR FOR 
       SELECT A 
       FROM MyTable
       WHERE B = @MyParam
  ...
  ...
  
  SET @MyParam = 2 ;
  ...
  ...
  OPEN My_Cur 
  
  WHILE ...
  BEGIN
  
      FETCH My_Cur INTO ...
  END;
  </code></pre>
  
  <p>When executing this, I get no results at all. If, instead of the variable in the cursor declaration, I deploy the value 2, results come out as needed.</p>
  
  <p>This works perfectly in other DBMS (e.g. ORACLE). </p>
  
  <p>Is it possible at all to have this type of parameterized cursors? If not, can anyone suggest a workaround?</p>
  
  <p>I found some posts suggesting to declare the cursor AFTER the value is assigned to the variable but... this looks to me a very strange limitation.</p>
  
  <p>Thanks.</p>