title: How to change cursor's select statement by some condition?
body: <p>Does any body know how to set different select statement for the same cursor? I need somethink like this.</p>
  
  <pre><code>DECLARE Temp_Cursor CURSOR FOR
  IF(@TempVar = 1)
  BEGIN
      SELECT CustomerId FROM Customers
  END
  ELSE IF(@TempVar = 2)
  BEGIN
      SELECT OrderId FROM Orders
  END
  OPEN Temp_Cursor;
  FETCH NEXT FROM TempCursor INTO @TempObjectId
  WHILE @@FETCH_STATUS = 0
  BEGIN 
  </code></pre>
  
  <p>.... etc</p>
  
  <p>I have found solution: <code>DECLARE @Temp_Cursor CURSOR
  IF(@TempVar = 1)
  BEGIN
      SET @Temp_Cursor = CURSOR FOR 
      SELECT CustomerId FROM Customers
  END
  ELSE IF(@TempVar = 2)
  BEGIN
        SET @Temp_Cursor = CURSOR FOR 
      SELECT OrderId FROM Orders
  END
  OPEN @Temp_Cursor;
  FETCH NEXT FROM @TempCursor INTO @TempObjectId
  WHILE @@FETCH_STATUS = 0
  BEGIN</code></p>