USE Northwind
declare Order_cursor cursor for
SELECT OrderID from Orders

open Order_cursor
declare @OrderID as INT
fetch next from Order_cursor into @OrderID
while(@@fetch_status =0)
begin
 PRINT 'OrderID' + STR(@OrderID)
  declare @SQLString nvarchar(500)
  set @SQLString =N'declare my_cursor cursor for select  ProductID from [Order Details] WHERE ORDERID=' + STR(@OrderID)
  exec sp_executesql  @SQLString


 open my_cursor
 declare @ProductID as INT
 fetch next from my_cursor into @ProductID
 while(@@fetch_status=0)
   begin
    
     PRINT 'ProductID:' + STR(@ProductID)
     fetch next from my_cursor into @ProductID
   end 
 
 close my_cursor
 deallocate my_cursor
 fetch next from Order_cursor into @OrderID
End
 
close Order_cursor
deallocate Order_cursor

相关文章:

  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
  • 2022-01-01
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-06-25
  • 2021-06-04
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
相关资源
相似解决方案