I'm having a problem with sp_msforeachdb throwing an error "Invalid column name 'USERCREATED'."
For the purpose of example, I've stripped back what I'm actually trying to achieve to this:
execute sp_msforeachdb 'if ((''?'' LIKE ''%CoLive'') or (''?'' LIKE ''%CoData''))
select ''?'' AS DBNAME,USERID,USERCREATED FROM USERS
Running this in SSMS the Results tab includes all three columns for both databases that match the LIKE selection. In the Messages tab I get the aforementioned error.