Update prices by 10% using a cursor

This problem asks the reader to write a cursor to update the prices of all products in a table by 10%. The table is provided as input, and the expected output is also shown.

Problem

Given a table of products and their prices, write a cursor to iterate over the table and update the prices of all products by 10%.
Input:
| Product | Price |
|---------|-------|
| A | $10 |
| B | $20 |
| C | $30 |
Output:
| Product | Price |
|---------|-------|
| A | $11 |
| B | $22 |
| C | $33 |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
/*

The optimal solution is to use a cursor to iterate over the table and update the prices of all products by 10%.

*/

DECLARE @Product VARCHAR(10)
DECLARE @Price DECIMAL(10,2)

DECLARE product_cursor CURSOR FOR
SELECT Product, Price
FROM Products

OPEN product_cursor

FETCH NEXT FROM product_cursor INTO @Product, @Price

WHILE @@FETCH_STATUS = 0
BEGIN
    UPDATE Products
    SET Price = @Price * 1.1
    WHERE Product = @Product

    FETCH NEXT FROM product_cursor INTO @Product, @Price
END

CLOSE product_cursor
DEALLOCATE product_cursor

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a level of completeness. The candidate has correctly used a cursor to iterate over the table and update the prices of all products by 10%. The candidate's approach is sound and the solution is efficient.

Evaluated at: 2022-11-27 04:16:16