title: SQL Server Cursor To Include the Value in Select
body: <p>I have a SELECT statement returning a set of rows.</p>
  
  <p>From each row, I need to get a value of one column and pass it to a Stored Procedure to get a value that I would need to supply for the set of rows itself.</p>
  
  <p>For example:</p>
  
  <pre><code>DECLARE @col1 int
  DECLARE @col2 int
  DECLARE @col3 varchar(20)
  
  DECLARE myCursor CURSOR FOR
  SELECT col1, col2, col3
  FROM table1
  WHERE....
  
  OPEN myCursor
  FETCH NEXT FROM myCursor
  INTO @col1, @col2
  
  WHILE @@FETH_STATUS = 0
  BEGIN
    SET @col3 = EXEC proc_GetCol3_Value @col1, @col2
  
    FETCH NEXT FROM myCursor
    INTO @col1, @col2
  END
  
  CLOSE myCursor
  DEALLOCATE myCursor
  </code></pre>
  
  <p>Now, based from that, I want to return the rows as retrieved by the original cursor, plus the value retrieved from the Stored procedure executed to be column 3's value.  </p>
  
  <p>Say, the rows returned by the SQL cursor is:</p>
  
  <pre><code>col1  col2  col3
    1   5000
    2   5000
    3   2500
    4   2000
  </code></pre>
  
  <p>And what I need is that all columns have been supplied after running the cursor and the Stored Proc and the result set should be:</p>
  
  <pre><code>col1  col2  col3
    1   5000  APPROVED
    2   5000  REJECTED
    3   2500  CANCELLED
    4   2000  APPROVED
  </code></pre>
  
  <p>Any ideas welcome. Thanks.</p>
  
  <p>P.S. I know that a lot would advice to simply using a JOIN statement but since the stored procedure to be executed is quite complex, making a join with the cursor SQL statement would be too complicated.</p>