Solved

How to list the database name alongside the current corresponding query results

Posted on 2016-08-08
2
42 Views
Last Modified: 2016-08-08
Heyas,

I have the following query:

DECLARE @command varchar(1000)
select @command = 'USE ?; select default_schema_name
, type_desc
, name
, create_date
from sys.database_principals
order by default_schema_name
, type_desc'
EXEC sp_MSforeachdb @command

Works fine.

My query is how to list the corresponding database for each of these existing result tests.

Any assistance is appreciated.

Thank you.
0
Comment
Question by:Zack
2 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 41746758
use DB_NAME():

DECLARE @command varchar(1000)
select @command = 'USE ?; select DB_NAME(), default_schema_name
, type_desc
, name
, create_date
from sys.database_principals
order by default_schema_name
, type_desc'
EXEC sp_MSforeachdb @command 

Open in new window

0
 

Author Closing Comment

by:Zack
ID: 41746765
Thank you just saved me a few hrs :). If you are able can you offer any insight into this query:

https://www.experts-exchange.com/questions/28961401/Configuring-a-maintenance-plan-or-scheduled-jobs-to-via-rules-set-by-the-resource-governor-Error-OLE-DB-error-code-0x80040E4D-Login-failed-for-user-'SQL-RG-MP-User'.html 

I have scoured google but I can't any meaning insights into my query.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now