该游标为实物配租记录赋房屋Id的值 --声明一个游标 declare my_cursor cursor for select h.id,h.swhouseaddress from lzhouse h,lzhouseleaseinfo hs where h.swhouseaddress=hs.renthouseaddress and h.swhouseusearea=hs.renthouseusearea and hs.houseid is null --打开游标 open my_cursor --声明变量 declare @hid numeric(19,0),@address varchar(200),@i int set @i=1 fetch next from my_cursor into @hid,@address while(@@fetch_status=0) begin print '第'+str(@i)+ '条:swHouseAddress: ' + @address set @i = @i +1 update lzhouseleaseinfo set houseid = @hid where renthouseaddress = @address fetch next from my_cursor into @hid,@address end --关闭游标 close my_cursor --删除游标 deallocate my_cursor