SP Cursor 記錄

  • 1302
  • 0

摘要:SP Cursor 記錄

 

if object_id('MyProCedure','P') is not null
drop proc MyProCedure
GO

Create proc [dbo].MyProCedure 
AS
declare mycursor cursor for SELECT CategoryName FROM Categories
declare @CategoryName nvarchar(30)
 

open mycursor
fetch next from mycursor into @CategoryName
while @@FETCH_STATUS=0
Begin
 print @CategoryName
 fetch next from mycursor into @CategoryName
end
close mycursor
deallocate mycursor