使用游标的情景基本上是在循环临时表里面的记录
// 声明一个游标
declare cursor1 cursor for select * from #temp1
//打开游标
open cursor1
// 把临时表里面值输入到变量里面
fetch next from cursor1 into @bookid,@price,@departmentid
while @@FETCH_STATUS = 0
begin
.........
fetch next from cursor1 into @bookid,@price,@departmentid
end
// 关闭游标
close cursor1
// 声明一个游标
declare cursor1 cursor for select * from #temp1
//打开游标
open cursor1
// 把临时表里面值输入到变量里面
fetch next from cursor1 into @bookid,@price,@departmentid
while @@FETCH_STATUS = 0
begin
.........
fetch next from cursor1 into @bookid,@price,@departmentid
end
// 关闭游标
close cursor1