View Full Version : Very slow cursor


SQL_Hell
04-03-2006, 01:04 AM
Hi guys,

I am having problems with the following cursor which is being run accross multipe sql servers, I will run ok on the first server but when it get to the next server it just hangs indefinately


declare @server varchar(50),
@servername varchar(50),
@drive char(1),
@sql varchar(200)

DECLARE server_cursor CURSOR STATIC FORWARD_ONLY
FOR SELECT distinct [srvname]
FROM [ho-msx-srv].master.dbo.sysservers s inner join SQLAnalysis.dbo.tblServerDrives t ON s.srvname = t.Servername
OPEN server_cursor
FETCH NEXT FROM server_cursor
INTO @server
WHILE @@FETCH_STATUS = 0
BEGIN

--select @server as server
set @sql = 'insert into SQLAnalysis.dbo.tblServerDrivesTMP exec ['+ @server + '].master.dbo.xp_fixeddrives'
--select @sql

exec(@sql)

select * from tblServerDrivesTMP



FETCH NEXT FROM server_cursor
INTO @server
END

CLOSE server_cursor
DEALLOCATE server_cursor




Any ideas?

pdx_man
04-04-2006, 10:10 AM
Is the other server on the same network and/or switch? Distributed transactions take a huge performance hit if they are not.