sp-msforeachdb

Help with sp_msforeachdb -like queries

Where I'm at we have a software package running on a mainframe system. The mainframe makes a nightly dump into sql server, such that each of our clients has it's own database in the server. There are a few other databases in the server instance as well, plus some older client dbs with no data. We often need to run reports or check da...

sp_MSforeachdb MS SQL error

This is for MS SQL 2005: Anyone know why the first succeeds, then creating two of the same statement in succession fails? All the statements are exactly the same. Changing the double quote to two single quotes has the same effect. sp_MSforeachdb @command1 = 'if (left("?", 2) = "p_") begin; print "?"; end;'; produces p_Na...

sp_MSforeachdb query help

Hi, I'm working with a lot of databases that are the same so I am using the sp_MSforeachdb procedure so that I can retrieve information from a table. The problem I have encountered is that there are other databases on the box that don't have the table, so I'm throwing invalid object errors. Here is What I have at the moment, I'm filte...