我需要获取所有应用程序数据库,并且我已经能够通过
select name from sys.database where database_id > 6
现在,我需要运行以下查询:
select
User_FirstName
, User_Name
, User_Id
, User_ReadAccess
from
[name obtained from sys.databases].dbo.ADMN_User_Details
这是我到目前为止所写的内容,但在以下位置出现错误database_Name.dbo.ADMN.User_Details
:
declare @database_name varchar(50)
declare @User_FirstName varchar (50)
declare @User_Name varchar (50)
declare @User_Access int
declare @User_Id varchar (50)
declare Maximizer cursor FOR
select name from sys.databases
where database_id > 6
open Maximizer
fetch next from Maximizer into @database_name
while (@@FETCH_STATUS=0)
begin
select
@User_FirstName, @User_Name, @User_Id, @User_Access
from
@database_Name.dbo.ADMN.User_Details
end
close Maximizer
deallocate Maximizer
有人可以在这里帮助我吗?
谢谢