declare @userid varchar(30)
set @userid = 'lairui'
declare @deptId varchar(500)
declare Deptid1 cursor for (select deptid from relationshipusers where userid = @userid )
--打开游标
open Deptid1
--从游标获取数据
fetch next from Deptid1 into @DeptID
--游标打开ok
while @@fetch_status=0
--。。。操作
--从游标获取下一项数据
begin
--循环操作开始
print 'sdfsf'
--循环操作结束
fetch next from Deptid1 into @DeptID
end
--关闭游标
close Deptid1
--释放游标
deallocate Deptid1
游标循环 游标的使用