[转]sql利用游标循环,遍历表循环结果集
用 游标(Cursor) + While循环 的方法, 对Customers表中的CompanyName列进行遍历 declare @customer nvarchar(50) declare pcurr cursor for select distinct companyname from customers open pcurr fetch next from pcurr into @customer while (@@fetch_status = 0) begin print (@customer) fetch next from pcurr into @customer end close pcurr deallocate pcurr