首页 > 数据库技术 > 详细

TSQL--游标Dem

时间:2014-01-17 19:03:25      阅读:476      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
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
bubuko.com,布布扣

TSQL--游标Dem

原文:http://www.cnblogs.com/TeyGao/p/3524293.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!