TSQL--游标Dem

DECLARE @ID INT;
DECLARE @Name NVARCHAR(200);
DECLARE @NewName NVARCHAR(200);

DECLARE MyCursor CURSOR FOR
SELECT TOP(100) ID,NAME1 FROM dbo.TB1
ORDER BY ID;


OPEN MyCursor

FETCH NEXT FROM MyCursor 
INTO @ID, @Name

WHILE @@FETCH_STATUS = 0
BEGIN

SET @NewName=@Name+CAST(@ID AS NVARCHAR(20))
UPDATE dbo.TB1
SET name1=@NewName
WHERE ID=@ID

PRINT @ID;
PRINT @NewName

FETCH NEXT FROM MyCursor 
INTO @ID, @Name
END

CLOSE MyCursor
DEALLOCATE MyCursor

 

posted on 2014-01-17 16:35  笑东风  阅读(212)  评论(0编辑  收藏  举报

导航