Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 how to exit from a cursor loop on a specified cond

Author  Topic 

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-08-20 : 03:02:28
HI ALL
i am using cursor to perform certain operation based on a value selected. If the value is null or 1 it should exist from the cursor

can anybody help me to solve this issue

thanks in advance
regards
DUrgesh j

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-08-20 : 04:00:20
Here is an example:

declare @checkval nvarchar(255)
declare test_cursor cursor for
select
[name]
from
sys.objects
open test_cursor
fetch next from test_cursor into @checkval
while @@fetch_status = 0 begin
print @checkval
-- Here comes the conditional exit
if @checkval = 'syscerts' begin
goto exitcursor
end
-- Here ends the conditional exit
fetch next from test_cursor into @checkval
end
exitcursor:
close test_cursor
deallocate test_cursor

Webfred

Planning replaces chance by mistake
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-20 : 04:01:21
use BREAK
Go to Top of Page
   

- Advertisement -