![[转]sql利用游标循环,遍历表循环结果集 [转]sql利用游标循环,遍历表循环结果集](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
用 游标(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