sp_MSforeachDB does not automatically change the context to each database, so it executes in the context of the database where you originally run the query. Preface your dynamic SQL with USE [?].
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA