Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Use sp_MSforeachdb but on a selected databases in the server

Posted on by 80

Hello. Please assist me. I am using sp_MSforeachdb and it is working so well with the below sytax:

DECLARE @command varchar(1000) 
SELECT @command = 
    'USE [?] exec sp_helpfile'         ---- exec sp_helpfile =query,you can replace how u wish.
EXEC sp_MSforeachdb @command

Now, my challenge is that there are a lot of databases (200) inside the server, some I do not have access to or they are not managed by me. So I want to use sp_MSforaechdb but only for the databases(20) that are of my responsibility. Please assist me with the syntax to include the loop on the above syntax that is already working.

Thanks

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans