使用Cursor 做逐筆update的動作

发表于:2007-05-25来源:作者:点击数: 标签:Cursor做逐動作UpdateUse
use testLeave GO DECLARE authors_cursor SCROLL CURSOR FOR SELECT EmployID, CONVERT(datetime,SUBSTRING(MV021,3,6),112) FROM CMSMV OPEN authors_cursor DECLARE @employid varchar(10) DECLARE @dayonjob datetime -- Fetch the last row in the curs

use testLeave
GO
DECLARE authors_cursor SCROLL CURSOR FOR
SELECT EmployID, CONVERT(datetime,SUBSTRING(MV021,3,6),112) FROM CMSMV

OPEN authors_cursor
DECLARE @employid varchar(10)
DECLARE @dayonjob datetime

-- Fetch the last row in the cursor.
FETCH FIRST FROM authors_cursor
into @employid, @dayonjob

UPDATE  CMSMV SET DateOnJob = @dayonjob where EmployID=@employid

WHILE @@FETCH_STATUS = 0
BEGIN

FETCH NEXT FROM authors_cursor
into @employid, @dayonjob
UPDATE  CMSMV SET DateOnJob = @dayonjob where EmployID=@employid

END

CLOSE authors_cursor
DEALLOCATE authors_cursor
GO

原文转自:http://www.ltesting.net