DECLARE @EmployeeName NVARCHAR(50)
DECLARE cursor_employee CURSOR FOR
SELECT EmployeeName FROM Employees
OPEN cursor_employee
FETCH NEXT FROM cursor_employee INTO @EmployeeName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @EmployeeName
FETCH NEXT FROM cursor_employee INTO @EmployeeName
END
CLOSE cursor_employee
DEALLOCATE cursor_employee
DECLARE cursor_forward CURSOR FORWARD_ONLY FOR
SELECT ProductName FROM Products
DECLARE cursor_static CURSOR STATIC FOR
SELECT CustomerName FROM Customers
DECLARE cursor_keyset CURSOR KEYSET FOR
SELECT OrderID FROM Orders
DECLARE cursor_dynamic CURSOR DYNAMIC FOR
SELECT SalesAmount FROM SalesData
DECLARE cursor_example CURSOR FOR
SELECT ProductName, UnitPrice FROM Products
DECLARE cursor_process CURSOR FOR
SELECT CustomerName, OrderAmount FROM Orders
OPEN cursor_process
FETCH NEXT FROM cursor_process INTO @CustomerName, @OrderAmount
WHILE @@FETCH_STATUS = 0
BEGIN
-- Process data here
FETCH NEXT FROM cursor_process INTO @CustomerName, @OrderAmount
END
CLOSE cursor_process
DEALLOCATE cursor_process