Please help me figure out why this script works everywhere except where it should.

Overview

Running a DTS Job accross multiple servers that checks database size. It's a modified sp_spaceused inside a cursor using sysdatabases. The script checks DB stats and inserts values per database into a table on another server.

Setup is:
1. DTS package create
2. Connections set to servers that need to be checked and the server containing the table for the stats.
3. ExecuteSQL Task created per target server
4. Save and Schedule package

Problem:
When running the script that reads the DB size stats in Query analyser, the select from sysdatabases used to populate the cursor works properly and values for each database on the target server are inserted into the stats table. The script also works properly when using "execute step" on a single step in DTS Designer. The script doesn't work when running multiple ExecuteSQL tasks in a DTS Package - It doesn't return db stats for some of the names that should be selected by the cursor on sysdatabases.

Script to check stats:

--declare @id int -- The object id of @objname.
--declare @type character(2) -- The object type.
declare @servername varchar(20)
declare @pages int -- Working variable for size calc.
declare @dbname sysname
declare @datapage dec(15,2)
declare @datapageMB dec(15,2)
declare @LogpageMB dec(15,2)
declare @logpage dec(15,2)
declare @unallocatedpage decimal(15,2)
declare @bytesperpage dec(15,2)
declare @pagesperMB dec(15,2)
DECLARE @DataPlusLogMB decimal(15,2)
DECLARE @Unallocated decimal(15,2)
declare @SQLstring nvarchar(4000)

-- Get the bytes per page
SELECT @bytesperpage = low
FROM master.dbo.spt_values
WHERE number = 1
AND type = 'E'

SET @pagesperMB = 1048576 / @bytesperpage

set @servername = 'Put Server Name Here'

DECLARE SpaceUsed CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases

OPEN SpaceUsed

FETCH NEXT FROM SpaceUsed
INTO @DBName


WHILE @@FETCH_STATUS = 0


begin
DBCC UPDATEUSAGE (@dbname) WITH NO_INFOMSGS
-- select @datapage = sum(convert(dec(15),size))
-- from @dbname.dbo.sysfiles
-- where (status & 64 = 0)
Set @SQLstring = 'select @datapage = sum(convert(dec(15),size)) '
Set @SQLstring = @SQLstring + 'from ' + @dbname + '.dbo.sysfiles '
Set @SQLstring = @SQLstring + 'where (status & 64 = 0)'

Print @SQLstring
exec sp_executesql @SQLstring, N'@datapage decimal(15,0) OUTPUT', @datapage OUTPUT
--select @dbname + ' Data Device: ' + cast(@datapage as varchar(20))
Print @dbname
-- select @logpage = sum(convert(dec(15),size))
-- from dbo.sysfiles
-- where (status & 64 <> 0)
Set @SQLString = 'select @logpage = sum(convert(dec(15),size)) '
Set @SQLString = @SQLString + 'from ' + @dbname + '.dbo.sysfiles '
Set @SQLString = @SQLString + 'where (status & 64 <> 0)'

Print @SQLstring
exec sp_executesql @SQLstring, N'@logpage decimal(15,0) OUTPUT', @logpage OUTPUT
--select @dbname + ' Log Device: ' + cast(@logpage as varchar(20))


Set @SQLString = 'SELECT @unallocatedpage = SUM(CAST(reserved AS decimal(15,0))) '
Set @SQLString = @SQLString + 'FROM '+ @dbname + '.dbo.sysindexes '
Set @SQLString = @SQLString + 'WHERE indid IN (0, 1, 255) '

Print @SQLstring
exec sp_executesql @SQLstring, N'@unallocatedpage decimal(15,0) OUTPUT', @unallocatedpage OUTPUT
--select @dbname + ' Unallocated: ' + cast(@unallocatedpage as varchar(20))


SET @DataPlusLogMB = (@datapage + @logpage) / @pagesperMB
SET @Unallocated =(@datapage - @unallocatedpage) / @pagesperMB
SET @DataPageMB = @datapage / @pagesperMB
SET @LogPageMB = @logpage / @pagesperMB

-- Change Server name Here - refer below

If not Exists (select * from <ServerName>.<DBName>.dbo.DatabaseStats
where DatabaseName like @DBName
and datediff(day, recorddate, getdate())=0)
Insert Into <ServerName>.<DBName>.dbo.DatabaseStats(ServerName ,DatabaseName, UsedSpace,FreeSpace,DataDevice, LogDevice, RecordDate)
Values(@servername, @dbname, @DataPlusLogMB,@Unallocated,@DataPageMB,@LogPageMB , getdate())




FETCH NEXT FROM SpaceUsed
INTO @DBName
END

CLOSE SpaceUsed
DEALLOCATE SpaceUsed

GO


And the script to create the table for the stats


CREATE TABLE [dbo].[DatabaseStats] (
[StatsID] [int] IDENTITY (1, 1) NOT NULL ,
[ServerName] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[DatabaseName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[UsedSpace] [decimal](18, 2) NULL ,
[FreeSpace] [decimal](18, 2) NULL ,
[DataDevice] [decimal](18, 2) NULL ,
[LogDevice] [decimal](18, 2) NULL ,
[RecordDate] [datetime] NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[DatabaseStats] WITH NOCHECK ADD
CONSTRAINT [PK_DatabaseStats] PRIMARY KEY CLUSTERED
(
[StatsID]
) ON [PRIMARY]
GO




Why, why? - it seems so simple but why doesn't it work.

G