I need the run the following query on many databases, I have over 100+ databases, but I don't want to pull up each database and run the query one at a time.
The User table is only listed in Database#_Account
.
If the query is ran it errors out because Database#_Admin
does not have User
Table.
(EXAMPLE Database List)
Database:
---------------------
MASTER
Model
msdb
tempdb
Database1_Account
Database1_Admin
Database2_Account
Database2_Admin
Database3_Account
Database3_Admin
Query:
EXEC sp_MsForEachDb @command1 = SELECT "?" as DatabaseName, *
FROM ?.User
WHERE Name = "John" AND "?" LIKE "%_Account"