To create a cursor in sql server
DECLARE @uid VARCHAR(500)
DECLARE @AgtName VARCHAR(500)
DECLARE curSample SCROLL CURSOR
FOR
SELECT UserID,AgentName FROM TestTable
OPEN curSample
FETCH NEXT FROM curSample INTO @uid,@AgtName
WHILE (@@FETCH_STATUS <> -1)
BEGIN
Update TestTable SET UserID='Test' WHERE UserID = @uid
FETCH NEXT FROM curSample INTO @uid,@AgtName
END
CLOSE curSample
DEALLOCATE curSample
DECLARE @uid VARCHAR(500)
DECLARE @AgtName VARCHAR(500)
DECLARE curSample SCROLL CURSOR
FOR
SELECT UserID,AgentName FROM TestTable
OPEN curSample
FETCH NEXT FROM curSample INTO @uid,@AgtName
WHILE (@@FETCH_STATUS <> -1)
BEGIN
Update TestTable SET UserID='Test' WHERE UserID = @uid
FETCH NEXT FROM curSample INTO @uid,@AgtName
END
CLOSE curSample
DEALLOCATE curSample
No comments:
Post a Comment