Hi,
Try this function to loop through all databases
--This query will return a listing of all tables in all databases on a SQL instance:
DECLARE @command varchar(1000)
SELECT @command = 'USE ? SELECT name FROM mycustomtable WHERE name = ''Foo'' ORDER BY name'
EXEC sp_MSforeachdb @command
This will run the SQL command for each database containing mycustomtable.
Hope this helps.