实现功能,利用游标循环表数据,并打印出来
表数据内容
实现的思路
实现代码:
declare @id nvarchar(200) declare @name nvarchar(150) declare @parentid nvarchar(200) declare data cursor for select id,name,parentid from sys_org open data fetch next from data into @id, @name, @parentid while (@@fetch_status = 0) begin -- 需要执行的语句 print 'id:'+@id +' name:'+@name +' parentid:'+ @parentid fetch next from data into @id, @name, @parentid end close data deallocate data
执行效果