SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Server 2005 SP2 Cursor does not complete


SQL Server 2005 SP2 Cursor does not complete

Author
Message
Les Sprott
Les Sprott
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 45
I am searching for help with a cursor that does not complete. it gives no errors and is random. When I run the SQL with commands commented out and view the results of the cursor it rolls through the data exactly like I want it to. when I uncomment the commands it executes it does 1/2 and then ends with success?

Has anyone else seen this behavior and know if there is a fix? Hehe
einman33
einman33
SSC Eights!
SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)

Group: General Forum Members
Points: 823 Visits: 512
Can you post source?
timothyawiseman
timothyawiseman
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

Group: General Forum Members
Points: 1442 Visits: 920
Can you provide more detail? Its hard to say much based on this so far.

---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Les Sprott
Les Sprott
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 45
The instance has eight databases and only backs up the first four and the jobs ends with no errors. it just does half of the databases in the cursor.

SET NOCOUNT ON
go
SET QUOTED_IDENTIFIER OFF
go
USE master
go

declare db_list_csr cursor for
select name
from sysdatabases
where name not in ('tempdb','Northwind','pubs')
order by name
go

declare @had_error bit
declare @currtime char(19)

declare @dbname varchar(45)
declare @file0 varchar(45), @file1 varchar(45), @file2 varchar(45)
declare @msg varchar(255)

/* Initialize stuff */
select @had_error = 0

open db_list_csr
fetch next from db_list_csr into @dbname
while @@fetch_status=0
begin
select @file0="g:\DBA\Backups\"+@dbname+".bak"

select @currtime = getdate()
select @msg = "Start dumping database "+@dbname+" at "+@currtime
print @msg

backup database @dbname to disk= @file0

if @@error = 0
begin
select @msg = "Database dump of "+@dbname+" completed at "+@currtime
print @msg
end
else
begin
select @had_error = 1
print "**********************************************************"
print "**********************************************************"
select @msg = "Database dump of "+@dbname+" failed at "+@currtime
print @msg
print "**********************************************************"
print "**********************************************************"
end
fetch next from db_list_csr into @dbname
end
close db_list_csr
deallocate db_list_csr

if @had_error = 1
goto error
else
print "That's all!"
return

error:

print "*******************************"
print "* DATABASE DUMPS HAD ERRORS *"
print "*******************************"
return
go
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search