you can do the following:
use master
declare @dbname varchar(100)
,@sql varchar(max)
create table #TempDBs (
dbname nvarchar(100)
, RecordCount int
)
declare db_cur cursor for
SELECT name
FROM master.dbo.sysdatabases where dbid>4
open db_cur
fetch next from db_cur...