Hi makumbi,
Refer below example.
Database
I have made use of the following table Customers with the schema as follows.
I have already inserted few records in the table.
You can download the database table SQL by clicking the download link below.
Download SQL file
SQL
DECLARE @CustomerId AS INT, @Name AS VARCHAR(50)
DECLARE @CurCustomerId AS VARCHAR(50)
SELECT @CustomerId = 1, @Name = 'John Hammond'
DECLARE UpdateCustomer CURSOR FOR
SELECT [Name]
FROM Customers
WHERE CustomerId = @CustomerId
OPEN UpdateCustomer
FETCH NEXT FROM UpdateCustomer INTO @CurCustomerId
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE Customers
SET [Name] = @Name
WHERE CURRENT OF UpdateCustomer
SELECT @CustomerId = @CustomerId + 1
FETCH NEXT FROM UpdateCustomer INTO @CurCustomerId
END;
CLOSE UpdateCustomer
DEALLOCATE UpdateCustomer