I am trying to run a stored procedure, sp_MSForEachDB in SQL but I want to exclude the system databases.
I have tried:
EXEC sp_MSForEachDB 'IF ''?'' Not In (''TEMPDB'', ''master'', ''model'', ''msdb'') use ? select top 10 * from tablename'
But it is still searching the system databases for a tablename that does not exist.
What am I doing something wrong?