-- 方法1:游标 -- 声明变量 DECLARE @address AS NVARCHAR(50), @neirong AS NVARCHAR(50); -- 声明游标 DECLARE C_MemberPhone CURSOR FAST_FORWARD FOR SELECT address,neirong FROM huiyi; --ORDER BY empid; OPEN C_MemberPhone; -- 取第一条记录 FETCH NEXT FROM C_MemberPhone INTO @address,@neirong; WHILE @@FETCH_STATUS=0 BEGIN -- 操作 UPDATE huiyi SET NewFiled= @address+‘ ‘+@neirong WHERE address=@address and neirong=@neirong; -- 取下一条记录 FETCH NEXT FROM C_MemberPhone INTO @address,@neirong; END -- 关闭游标 CLOSE C_MemberPhone; -- 释放游标 DEALLOCATE C_MemberPhone;
时间: 2024-10-13 20:52:57