Isabella
---- I fell upon the thorn of life, I bleed.

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

posted on 2007-06-05 16:54  李昀璟  阅读(801)  评论(1)    收藏  举报