SQL Server 游标更新

USE AdventureWorks2008R2;

GO

DECLARE complex_cursor CURSOR FOR

    SELECT a.BusinessEntityID

    FROM HumanResources.EmployeePayHistory AS a

    WHERE RateChangeDate <> 

         (SELECT MAX(RateChangeDate)

          FROM HumanResources.EmployeePayHistory AS b

          WHERE a.BusinessEntityID = b.BusinessEntityID) ;

OPEN complex_cursor;

FETCH FROM complex_cursor;

UPDATE HumanResources.EmployeePayHistory

SET PayFrequency = 2 

WHERE CURRENT OF complex_cursor;

CLOSE complex_cursor;

DEALLOCATE complex_cursor;

GO

你可能感兴趣的:(SQL Server)