Invalid object name 'sysdatabases'.

Posted on 2006-05-09
Last Modified: 2013-12-28
I am trying to creat a job to run the following script at month end. This was working until a total server rebuild. Now I get the following error the Invalid object name 'sysdatabases'. [SQLSTATE 42S02] (Error 208). I did not write the script but this is it. sysdatabases does exist in the master DB. Could this be some permission issue?

DECLARE @statement NVARCHAR(1000)

This cursor will collect all the databases names that begin with "PB_" .

DECLARE dbnames cursor for select name from sysdatabases where name like 'PB_0506_1%'
select @rundate = (select convert(varchar(2),datepart(month,getdate())) + '/1/' + convert(char(4),datepart(year,getdate())))

/* Open the cursor to begin working with each database name */
open dbnames

/* Fetch the first database name from the cursor before going into the while loop */
FETCH next from dbnames into @dbname

/* Loop through the cursor until the fetch status is not zero or done with all database names */


   if ( select count(*) from eom.dbo.usertotals where dbname = @dbname and rundate=@rundate) > 0 goto skipped

   set @statement = N'declare @totalusers INT' + char(13)
                    + N'declare @rundate datetime' + char(13)
                    + N'declare @bpusers INT' + char(13)
                    + N'select @totalusers = (select count(customernumber) from ' + @dbname + '.dbo.usersecurity)' + char(13)
                    + N'select @rundate = (select convert(varchar(2),datepart(month,getdate())) + ''/1/'' + convert(char(4),datepart(year,getdate())))' + char(13)
                    + N'insert into eom.dbo.usertotals values(''' + @dbname + N''',@rundate,@totalusers,0,NULL)' + char(13)
                    + N'select @bpusers = (select count(customernumber) from ' + @dbname + '.dbo.usermisc where billpayaccess=''Y'')' + char(13)
                    + N'update eom.dbo.usertotals set bpusers = @bpusers where rundate=@rundate and dbname=''' + @dbname + N'''' + char(13)

   exec (@statement)


   /* Get the next database name and continue the loop. */
   FETCH next from dbnames into @dbname

close dbnames
deallocate dbnames
Question by:CUOL-MIS
    LVL 142

    Accepted Solution

    DECLARE dbnames cursor for select name from master.dbo.sysdatabases where name like 'PB_0506_1%'

    Author Comment

    Thank you for the quick response! That did the trick.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    A few months ago I had an issue with LaserJet 1020 printer which was installed to XP and Windows 7.  It was installed to XP and working, but when I tried to connect from a Windows 7 PC, it would attempt connection and then fail.  Sometimes the Spool…
    The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now