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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。