-- 声明变量 DECLARE @Id NVARCHAR(100) DECLARE @index int set @index=1 -- 声明游标 DECLARE MyCursor CURSOR FOR select Id from Sheet3 -- 打开游标 OPEN MyCursor -- 从游标中取得第一行数据 FETCH NEXT FROM MyCursor INTO @Id -- 循环遍历游标中的所有行 WHILE @@FETCH_STATUS = 0 BEGIN -- 处理每行数据的逻辑 -- ... update Sheet3 set barcode = 'HD240328' + FORMAT(@index, '00000') where Id=@Id -- 将处理后的数据插入临时表 set @index=@index+1 print(@index) -- 获取下一行数据 FETCH NEXT FROM MyCursor INTO @Id END -- 关闭游标并释放资源 CLOSE MyCursor -- 师傅游标 DEALLOCATE MyCursor
标签:index,set,--,游标,MyCursor,Sql,Id,Sever From: https://www.cnblogs.com/zoro-zero/p/18101484