Cursor creation
<p>I have 2 tables:  </p>

<p>Tresent-JanOrg (Rate, Qty)</p>

<pre><code>Rate (2, 5, 7)
Qty  (3, 7, 7)
</code></pre>

<p>Temp (JanOrg)</p>

<pre><code>Pkid JanOrg FebOrg MarOrg
1     2        0     0
</code></pre>

<p>I have to do the calculations 3 times (3 rows in Tresent) to calculate </p>

<pre><code>JanOrg = (JanOrg * Qty * Rate) / 100 
</code></pre>

<p>and the total of janorg should then be updated in temp table under janorg</p>

<p>So logically </p>

<pre><code>JanOrg = ((2 * 2 * 3) / 100) + ((2 * 5 * 7) / 100) + ((2 * 3 * 7) / 100)))
</code></pre>

<p>I am trying to use a cursor in SQL Server 2012 but it is not returning correct results</p>

<p>Can you please suggest the better way of performing these calculations as i tried the below code : </p>

<pre><code>OPEN complex_cursor

FETCH NEXT FROM complex_cursor INTO @rate, @qty

WHILE @@FETCH_STATUS = 0
BEGIN
    UPDATE #temp 
    SET JANORG = (JANORG * @rate * @qty) / 100 

    FETCH NEXT FROM complex_cursor INTO @rate, @qty
END

CLOSE complex_cursor
DEALLOCATE complex_cursor
</code></pre>